<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: ilogic code for view labelling in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-code-for-view-labelling/m-p/10813520#M42477</link>
    <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4278250"&gt;@rankinkane&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only part of you request that requires further information is how to find the correct assembly to get item number for the part.&amp;nbsp; If you can help me understand how the part/drawing/assembly are associated we can find the Item number.&amp;nbsp; For the rest of the code see the following:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;'Anything Outside The 'main' routine only runs when called
Sub Main
	'Try to set Active Document to a DrawingDocument Object
	Dim dDoc As DrawingDocument = TryCast(ThisApplication.ActiveDocument, DrawingDocument) 'This Fails to Nothing
	If IsNothing(dDoc) Then Logger.Debug("Not A DrawingDocuemnt") : Exit Sub
	'We know we have a drawing document open
	'Get User to select a view
	Dim PickView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a View")
	If IsNothing(PickView) Then Exit Sub 'If nothing gets selected then we're done
	'We now have a drawing view
	'Call routine for the selected view.
	Call ViewInfo(PickView)
	'Breaking up code like this helps for multipurposing.
	'If you want you can loop through all the views on a sheet
End Sub

'Sub Routine: Processes Custom Options for a given DrawingView Object
Sub ViewInfo(dView As DrawingView)
	'Define some Objects
	Dim ModelDoc As Document = dView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim ItemNumber As String 'I will need more information to make this work
	Dim mPartNumber As String 'ModelDocument PartNumber
	Dim smThickness As String 'SheetMetal Thickness As a number 
	Dim mMaterial As String 'ModelDocument Material

	'Try to set the model document to a PartDocument Object
	Dim pDoc As PartDocument = TryCast(ModelDoc, PartDocument)
	If Not IsNothing(pDoc) 'As long as it is anything/not nothing
		ItemNumber = FindAssemblyItemNumber(pDoc) 'Call Custom Function to get Item Number
		mPartNumber = pDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value 'Get PartNumber iProperty
		smThickness = GetSheetMetalThickness(pDoc) 'Call Custom Function to get Sheet Metal Thickness [I'm going to return mm]
		mMaterial = pDoc.ActiveMaterial.DisplayName
		'Now I am sending the gathered information to the drawingview label.
		'If you want to put it somehwere else, let me know
		Call SetLabel(dView, ItemNumber, mPartNumber, smThickness, mMaterial) 'Custom Sub Routine
	End If
	
End Sub

'Sub Routine: Sets the DrawingView Label to a custom string format, centered &amp;amp; bottom of view for a given DrawingView Object
Sub SetLabel(dView As DrawingView, s1 As String, s2 As String, s3 As String, s4 As String)
	Dim ThisSheet As Sheet = dView.Parent 'Get The Sheet the view is on
	'Set Text to dsiplay
	Dim FormattedText As String = "&amp;lt;StyleOverride Underline='True'&amp;gt;" &amp;amp; s1 &amp;amp; " - " &amp;amp; s2 &amp;amp; "&amp;lt;/StyleOverride&amp;gt;&amp;lt;Br/&amp;gt;" &amp;amp; s3 &amp;amp; s4 
	'SetThe DrawingView Label &amp;amp; make sure it is visible &amp;amp; @ Bottom Center
	dView.ShowLabel = True
	Dim dvLabel As DrawingViewLabel = dView.Label
	dvLabel.FormattedText = FormattedText
	dvLabel.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
	dvLabel.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextLower
End Sub

'A Function sends something back after being called. It gets defined like any other Object
'Function: Return {AS String} Item number of given part document in Assembly. {assembly currently unknown}
Function FindAssemblyItemNumber(pDoc As PartDocument) As String
	Dim Result As String = "Need Assembly Info" 'Defualt Result
	
	'I need more information to find the correct assmebly from a partdocument drawing view
	
	Return Result
End Function

'Function: Return {AS String} SheetMetal Thickness for given PartDocument Object
Function GetSheetMetalThickness(pDoc As PartDocument) As String
	Dim Result As String = "" 'Defualt Result
	Dim ResultValue As Double 'Set Object For Double Handling
	
	'Try to set a SheetMetalComponentDefinition Object
	Dim smDef As SheetMetalComponentDefinition = TryCast(pDoc.ComponentDefinition, SheetMetalComponentDefinition)
	If IsNothing(smDef) Then Return Result 'If The PartDocument is not a sheetmetal part return our 'nothing' default
		
	'We know we have a view of a sheetmetal Part and can call Specific Properties and methods
	ResultValue = smDef.Thickness.Value 'Database units for Length is cm. We have to convert to our desired unit type
	ResultValue *= 10 'I'm converting the value from cm to mm by multiplying itself by 10
	'I'm going to return mm with 3 decimals
	Result = Math.Round(ResultValue, 3).ToString &amp;amp; " mm "
	
	Return Result
End Function&lt;/LI-CODE&gt;&lt;P&gt;After running the rule you will be asked to select a DrawingView&amp;nbsp; [this could easily be adapted to run for every DrawingView on a given sheet, or even every DrawingView on every sheets].&amp;nbsp; I wrote it in a modular structure, as it allows for easier adaptation to various processes.&amp;nbsp; The label is structured as shown in the image posted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if you have any questions, as you stated you are new to coding.&amp;nbsp; Also let me know how to relate an assembly to a particular part in a particular drawing.&lt;/P&gt;</description>
    <pubDate>Fri, 10 Dec 2021 04:39:55 GMT</pubDate>
    <dc:creator>J-Camper</dc:creator>
    <dc:date>2021-12-10T04:39:55Z</dc:date>
    <item>
      <title>ilogic code for view labelling</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-code-for-view-labelling/m-p/10813389#M42475</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am very new to coding and I would like to know if there is a way to use code to add set values to a drawing view. Mainly for use with flat patterns but I would also like to use it for standard parts and just drop the thickness value.&lt;/P&gt;&lt;P&gt;I would like to add these parameters;&lt;/P&gt;&lt;P&gt;Item number from parts list,&lt;/P&gt;&lt;P&gt;part number,&lt;/P&gt;&lt;P&gt;sheet metal thickness,&lt;/P&gt;&lt;P&gt;and material.&lt;/P&gt;&lt;P&gt;Like this&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rankinkane_0-1639103068595.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/999645i0158CE41D870D0DD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="rankinkane_0-1639103068595.png" alt="rankinkane_0-1639103068595.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If anyone could help me out that would be great.&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 02:26:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-code-for-view-labelling/m-p/10813389#M42475</guid>
      <dc:creator>rankinkane</dc:creator>
      <dc:date>2021-12-10T02:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: ilogic code for view labelling</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-code-for-view-labelling/m-p/10813428#M42476</link>
      <description>&lt;P&gt;Here is a few links, you will need to work with the view.label.formattedtext. The view.name is the name given to the view in dialogue used for setting up the view.&amp;nbsp; You can either just add the property values as text or add link properties (much harder ) that will update when the model changes. You can already add a lot of these all ready manually in the drawing templates.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a simple one to get you started&lt;/P&gt;&lt;P&gt;&lt;A href="http://forums.autodesk.com/t5/inventor-customization/ilogic-code-to-change-view-label-text/td-p/3625130" target="_blank" rel="noopener"&gt;http://forums.autodesk.com/t5/inventor-customization/ilogic-code-to-change-view-label-text/td-p/3625...&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
If oSSet.count = 0 Then
	MessageBox.Show("You must select a drawing view first", "iLogic")
Exit Sub
End If

'Reference to the drawing view from the 1st selected object
Dim oView As DrawingView = trycast(oSSet.item(1), DrawingView)

If oView IsNot Nothing Then
oView.ShowLabel = True
'format the model iproperties	
oDescription = "&amp;lt;StyleOverride Underline='True'&amp;gt;&amp;lt;Property Document='model' PropertySet='Design Tracking Properties' Property='Description' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='29'&amp;gt;DESCRIPTION&amp;lt;/Property&amp;gt;&amp;lt;/StyleOverride&amp;gt;"
oPartNumber = "&amp;lt;StyleOverride Underline='True'&amp;gt; - Mk &amp;lt;Property Document='model' PropertySet='Design Tracking Properties' Property='Part Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'&amp;gt;PART NUMBER&amp;lt;/Property&amp;gt;&amp;lt;/StyleOverride&amp;gt;"
oStringMass = "&amp;lt;Br/&amp;gt;&amp;lt;StyleOverride Underline='False' FontSize='0.35'&amp;gt;EST UNIT MASS = &amp;lt;PhysicalProperty PhysicalPropertyID='72449' Precision='2'&amp;gt;MASS&amp;lt;/PhysicalProperty&amp;gt;&amp;lt;/StyleOverride&amp;gt;"
oStringScale = "&amp;lt;Br/&amp;gt;&amp;lt;StyleOverride FontSize='0.3'&amp;gt;(Scale &amp;lt;DrawingViewScale/&amp;gt;)&amp;lt;/StyleOverride&amp;gt;"

'add to the view label
oView.Label.FormattedText =  oDescription &amp;amp; oPartNumber &amp;amp; oStringMass &amp;amp; oStringScale	    

Else
	MessageBox.Show("The selected object is not a drawing view", "iLogic")
End If&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;This one shows more detail on getting custom attributes into the view label.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://forums.autodesk.com/t5/inventor-customization/custom-user-properties-in-view-label-of-drawing-template-style/td-p/3420537" target="_blank" rel="noopener"&gt;http://forums.autodesk.com/t5/inventor-customization/custom-user-properties-in-view-label-of-drawing...&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And this one will work with assemblies.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://blog.ads-sol.com/2016/02/item-number-on-drawing-views-reg-hasell.html" target="_blank"&gt;http://blog.ads-sol.com/2016/02/item-number-on-drawing-views-reg-hasell.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 03:00:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-code-for-view-labelling/m-p/10813428#M42476</guid>
      <dc:creator>A.Acheson</dc:creator>
      <dc:date>2021-12-10T03:00:59Z</dc:date>
    </item>
    <item>
      <title>Re: ilogic code for view labelling</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-code-for-view-labelling/m-p/10813520#M42477</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4278250"&gt;@rankinkane&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only part of you request that requires further information is how to find the correct assembly to get item number for the part.&amp;nbsp; If you can help me understand how the part/drawing/assembly are associated we can find the Item number.&amp;nbsp; For the rest of the code see the following:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;'Anything Outside The 'main' routine only runs when called
Sub Main
	'Try to set Active Document to a DrawingDocument Object
	Dim dDoc As DrawingDocument = TryCast(ThisApplication.ActiveDocument, DrawingDocument) 'This Fails to Nothing
	If IsNothing(dDoc) Then Logger.Debug("Not A DrawingDocuemnt") : Exit Sub
	'We know we have a drawing document open
	'Get User to select a view
	Dim PickView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a View")
	If IsNothing(PickView) Then Exit Sub 'If nothing gets selected then we're done
	'We now have a drawing view
	'Call routine for the selected view.
	Call ViewInfo(PickView)
	'Breaking up code like this helps for multipurposing.
	'If you want you can loop through all the views on a sheet
End Sub

'Sub Routine: Processes Custom Options for a given DrawingView Object
Sub ViewInfo(dView As DrawingView)
	'Define some Objects
	Dim ModelDoc As Document = dView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim ItemNumber As String 'I will need more information to make this work
	Dim mPartNumber As String 'ModelDocument PartNumber
	Dim smThickness As String 'SheetMetal Thickness As a number 
	Dim mMaterial As String 'ModelDocument Material

	'Try to set the model document to a PartDocument Object
	Dim pDoc As PartDocument = TryCast(ModelDoc, PartDocument)
	If Not IsNothing(pDoc) 'As long as it is anything/not nothing
		ItemNumber = FindAssemblyItemNumber(pDoc) 'Call Custom Function to get Item Number
		mPartNumber = pDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value 'Get PartNumber iProperty
		smThickness = GetSheetMetalThickness(pDoc) 'Call Custom Function to get Sheet Metal Thickness [I'm going to return mm]
		mMaterial = pDoc.ActiveMaterial.DisplayName
		'Now I am sending the gathered information to the drawingview label.
		'If you want to put it somehwere else, let me know
		Call SetLabel(dView, ItemNumber, mPartNumber, smThickness, mMaterial) 'Custom Sub Routine
	End If
	
End Sub

'Sub Routine: Sets the DrawingView Label to a custom string format, centered &amp;amp; bottom of view for a given DrawingView Object
Sub SetLabel(dView As DrawingView, s1 As String, s2 As String, s3 As String, s4 As String)
	Dim ThisSheet As Sheet = dView.Parent 'Get The Sheet the view is on
	'Set Text to dsiplay
	Dim FormattedText As String = "&amp;lt;StyleOverride Underline='True'&amp;gt;" &amp;amp; s1 &amp;amp; " - " &amp;amp; s2 &amp;amp; "&amp;lt;/StyleOverride&amp;gt;&amp;lt;Br/&amp;gt;" &amp;amp; s3 &amp;amp; s4 
	'SetThe DrawingView Label &amp;amp; make sure it is visible &amp;amp; @ Bottom Center
	dView.ShowLabel = True
	Dim dvLabel As DrawingViewLabel = dView.Label
	dvLabel.FormattedText = FormattedText
	dvLabel.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
	dvLabel.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextLower
End Sub

'A Function sends something back after being called. It gets defined like any other Object
'Function: Return {AS String} Item number of given part document in Assembly. {assembly currently unknown}
Function FindAssemblyItemNumber(pDoc As PartDocument) As String
	Dim Result As String = "Need Assembly Info" 'Defualt Result
	
	'I need more information to find the correct assmebly from a partdocument drawing view
	
	Return Result
End Function

'Function: Return {AS String} SheetMetal Thickness for given PartDocument Object
Function GetSheetMetalThickness(pDoc As PartDocument) As String
	Dim Result As String = "" 'Defualt Result
	Dim ResultValue As Double 'Set Object For Double Handling
	
	'Try to set a SheetMetalComponentDefinition Object
	Dim smDef As SheetMetalComponentDefinition = TryCast(pDoc.ComponentDefinition, SheetMetalComponentDefinition)
	If IsNothing(smDef) Then Return Result 'If The PartDocument is not a sheetmetal part return our 'nothing' default
		
	'We know we have a view of a sheetmetal Part and can call Specific Properties and methods
	ResultValue = smDef.Thickness.Value 'Database units for Length is cm. We have to convert to our desired unit type
	ResultValue *= 10 'I'm converting the value from cm to mm by multiplying itself by 10
	'I'm going to return mm with 3 decimals
	Result = Math.Round(ResultValue, 3).ToString &amp;amp; " mm "
	
	Return Result
End Function&lt;/LI-CODE&gt;&lt;P&gt;After running the rule you will be asked to select a DrawingView&amp;nbsp; [this could easily be adapted to run for every DrawingView on a given sheet, or even every DrawingView on every sheets].&amp;nbsp; I wrote it in a modular structure, as it allows for easier adaptation to various processes.&amp;nbsp; The label is structured as shown in the image posted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if you have any questions, as you stated you are new to coding.&amp;nbsp; Also let me know how to relate an assembly to a particular part in a particular drawing.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 04:39:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-code-for-view-labelling/m-p/10813520#M42477</guid>
      <dc:creator>J-Camper</dc:creator>
      <dc:date>2021-12-10T04:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: ilogic code for view labelling</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-code-for-view-labelling/m-p/10814249#M42478</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4278250"&gt;@rankinkane&lt;/a&gt;&amp;nbsp;kindly go through these quick tutorials for ilogic with inventor. Let me know in case of any clarification&lt;/P&gt;
&lt;P&gt;For drawing views&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GUID-66470F9F-8563-4D53-91BE-F4769943E71C" target="_blank"&gt;Inventor 2022 Help | Drawing Views | Autodesk&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;For dimensions&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GUID-968D16DA-408E-4ED8-A87A-EE8972C644F5" target="_blank"&gt;Inventor 2022 Help | Drawing Dimensions | Autodesk&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;For adding Balloons&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GUID-638E2791-8400-4F7F-80E0-9304849CF1C3" target="_blank"&gt;Inventor 2022 Help | Balloons | Autodesk&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;For adding custom tables&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GUID-C15AC636-5D84-40A8-88A4-B2AEDD0A3DDB" target="_blank"&gt;Inventor 2022 Help | Custom Tables | Autodesk&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 11:34:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-code-for-view-labelling/m-p/10814249#M42478</guid>
      <dc:creator>fidel.makatiaD5W7V</dc:creator>
      <dc:date>2021-12-10T11:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: ilogic code for view labelling</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-code-for-view-labelling/m-p/10816698#M42479</link>
      <description>&lt;P&gt;Thanks very much for your time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I probably should have lead the enquiry with this but I have some code for extracting the item number and scale for the views. I would like to replace what I have with the information provided on the original post.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code I have so far.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oDrawDoc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;DrawingDocument&lt;/SPAN&gt;
&lt;SPAN&gt;oDrawDoc&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;ActiveDocument&lt;/SPAN&gt;

&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oSheets&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Sheets&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;Sheet&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Inventor&lt;/SPAN&gt;.&lt;SPAN&gt;Sheet&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oViews&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;DrawingViews&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oView&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;DrawingView&lt;/SPAN&gt;

&lt;SPAN&gt;For&lt;/SPAN&gt; &lt;SPAN&gt;Each&lt;/SPAN&gt; &lt;SPAN&gt;oSheet&lt;/SPAN&gt; &lt;SPAN&gt;In&lt;/SPAN&gt; &lt;SPAN&gt;oDrawDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Sheets&lt;/SPAN&gt;
&lt;SPAN&gt;'For Each oSheet In oSheets&lt;/SPAN&gt;
    &lt;SPAN&gt;oViews&lt;/SPAN&gt; = &lt;SPAN&gt;oSheet&lt;/SPAN&gt;.&lt;SPAN&gt;DrawingViews&lt;/SPAN&gt;
    &lt;SPAN&gt;For&lt;/SPAN&gt; &lt;SPAN&gt;Each&lt;/SPAN&gt; &lt;SPAN&gt;oView&lt;/SPAN&gt; &lt;SPAN&gt;In&lt;/SPAN&gt; &lt;SPAN&gt;oViews&lt;/SPAN&gt;
   
        &lt;SPAN&gt;'Get the full filename Of the view model&lt;/SPAN&gt;
        &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oModelFileName&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;String&lt;/SPAN&gt;
        &lt;SPAN&gt;oModelFileName&lt;/SPAN&gt; = &lt;SPAN&gt;oView&lt;/SPAN&gt;.&lt;SPAN&gt;ReferencedDocumentDescriptor&lt;/SPAN&gt;.&lt;SPAN&gt;ReferencedDocument&lt;/SPAN&gt;.&lt;SPAN&gt;FullFileName&lt;/SPAN&gt;
        &lt;SPAN&gt;'MessageBox.Show("view model name" &amp;amp; oModelFileName, "Title")&lt;/SPAN&gt;

        &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oPartList&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;PartsList&lt;/SPAN&gt;
            &lt;SPAN&gt;'try and get the parts list form the table of this sheet&lt;/SPAN&gt;
            &lt;SPAN&gt;Try&lt;/SPAN&gt;
                &lt;SPAN&gt;oPartList&lt;/SPAN&gt; = &lt;SPAN&gt;oDrawDoc&lt;/SPAN&gt;.&lt;SPAN&gt;ActiveSheet&lt;/SPAN&gt;.&lt;SPAN&gt;PartsLists&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(1)
            &lt;SPAN&gt;Catch&lt;/SPAN&gt; &lt;SPAN&gt;'on error try and search all sheets for first found parts list           &lt;/SPAN&gt;
                &lt;SPAN&gt;'iterate trough each sheet&lt;/SPAN&gt;
                &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;i&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Long&lt;/SPAN&gt;
                &lt;SPAN&gt;For&lt;/SPAN&gt; &lt;SPAN&gt;i&lt;/SPAN&gt; = 1 &lt;SPAN&gt;To&lt;/SPAN&gt; &lt;SPAN&gt;oDrawDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Sheets&lt;/SPAN&gt;.&lt;SPAN&gt;Count&lt;/SPAN&gt;
                    &lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;oDrawDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Sheets&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;i&lt;/SPAN&gt;).&lt;SPAN&gt;PartsLists&lt;/SPAN&gt;.&lt;SPAN&gt;Count&lt;/SPAN&gt; &amp;gt; 0 &lt;SPAN&gt;Then&lt;/SPAN&gt; &lt;SPAN&gt;Exit&lt;/SPAN&gt; &lt;SPAN&gt;For&lt;/SPAN&gt;
                &lt;SPAN&gt;Next&lt;/SPAN&gt;   
                &lt;SPAN&gt;oPartList&lt;/SPAN&gt; = &lt;SPAN&gt;oDrawDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Sheets&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;i&lt;/SPAN&gt;).&lt;SPAN&gt;PartsLists&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(1)
                &lt;SPAN&gt;'MessageBox.Show("parts list found on: " &amp;amp; i, "Title")&lt;/SPAN&gt;
            &lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Try&lt;/SPAN&gt;
               
            &lt;SPAN&gt;' Iterate through the contents of the parts list.&lt;/SPAN&gt;
            &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;j&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Long&lt;/SPAN&gt;
            &lt;SPAN&gt;For&lt;/SPAN&gt; &lt;SPAN&gt;j&lt;/SPAN&gt; = 1 &lt;SPAN&gt;To&lt;/SPAN&gt; &lt;SPAN&gt;oPartList&lt;/SPAN&gt;.&lt;SPAN&gt;PartsListRows&lt;/SPAN&gt;.&lt;SPAN&gt;Count&lt;/SPAN&gt;
                &lt;SPAN&gt;' Get the current row.&lt;/SPAN&gt;
                &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oRow&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;PartsListRow&lt;/SPAN&gt;
                &lt;SPAN&gt;oRow&lt;/SPAN&gt; = &lt;SPAN&gt;oPartList&lt;/SPAN&gt;.&lt;SPAN&gt;PartsListRows&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;j&lt;/SPAN&gt;)
                &lt;SPAN&gt;'get filename of model in row&lt;/SPAN&gt;
                &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oRowFileName&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;String&lt;/SPAN&gt;
                &lt;SPAN&gt;oRowFileName&lt;/SPAN&gt; = &lt;SPAN&gt;oRow&lt;/SPAN&gt;.&lt;SPAN&gt;ReferencedFiles&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(1).&lt;SPAN&gt;FullFileName&lt;/SPAN&gt;
                &lt;SPAN&gt;'compare the filenames&lt;/SPAN&gt;
                &lt;SPAN&gt;'Performs a text comparison, based on a case-insensitive text sort order&lt;/SPAN&gt;
                &lt;SPAN&gt;'If strings equal returns 0&lt;/SPAN&gt;
                &lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;StrComp&lt;/SPAN&gt;(&lt;SPAN&gt;oModelFileName&lt;/SPAN&gt;, &lt;SPAN&gt;oRowFileName&lt;/SPAN&gt;, &lt;SPAN&gt;CompareMethod&lt;/SPAN&gt;.&lt;SPAN&gt;Text&lt;/SPAN&gt;)=0 &lt;SPAN&gt;Then&lt;/SPAN&gt;
                    &lt;SPAN&gt;'Get the value of Item from the Parts List&lt;/SPAN&gt;
                    &lt;SPAN&gt;'Row name needs to be case sensitive or use 1 for first 2 for second etc.&lt;/SPAN&gt;
                    &lt;SPAN&gt;oCell&lt;/SPAN&gt;  = &lt;SPAN&gt;oPartList&lt;/SPAN&gt;.&lt;SPAN&gt;PartsListRows&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;j&lt;/SPAN&gt;).&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;"Item"&lt;/SPAN&gt;) &lt;SPAN&gt;'Row name needs to be case sensitive or use 1 for first 2 for second etc.&lt;/SPAN&gt;
                    &lt;SPAN&gt;'get the value of text in cell&lt;/SPAN&gt;
                    &lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oItemValue&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;String&lt;/SPAN&gt;
                    &lt;SPAN&gt;oItemValue&lt;/SPAN&gt; = &lt;SPAN&gt;oCell&lt;/SPAN&gt;.&lt;SPAN&gt;Value&lt;/SPAN&gt;
                   
                    &lt;SPAN&gt;'Show the view label&lt;/SPAN&gt;
                    &lt;SPAN&gt;oView&lt;/SPAN&gt;.&lt;SPAN&gt;ShowLabel&lt;/SPAN&gt; = &lt;SPAN&gt;True&lt;/SPAN&gt;
                    &lt;SPAN&gt;'format the text first line&lt;/SPAN&gt;
                    &lt;SPAN&gt;oStringItem&lt;/SPAN&gt; = &lt;SPAN&gt;"&amp;lt;StyleOverride Underline='True' FontSize='0.35'&amp;gt; ITEM "&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;oItemValue&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;" &amp;lt;/StyleOverride&amp;gt;"&lt;/SPAN&gt;
                    &lt;SPAN&gt;'format the text second line&lt;/SPAN&gt;
                    &lt;SPAN&gt;oStringScale&lt;/SPAN&gt; = &lt;SPAN&gt;"&amp;lt;Br/&amp;gt;&amp;lt;StyleOverride FontSize='0.3'&amp;gt;(Scale &amp;lt;DrawingViewScale/&amp;gt;)&amp;lt;/StyleOverride&amp;gt;"&lt;/SPAN&gt;
                   
                    &lt;SPAN&gt;'add to the view label&lt;/SPAN&gt;
                    &lt;SPAN&gt;oView&lt;/SPAN&gt;.&lt;SPAN&gt;Label&lt;/SPAN&gt;.&lt;SPAN&gt;FormattedText&lt;/SPAN&gt; =  &lt;SPAN&gt;oStringItem&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;oStringScale&lt;/SPAN&gt;
                &lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt; 
            &lt;SPAN&gt;Next&lt;/SPAN&gt;
      &lt;SPAN&gt;Next&lt;/SPAN&gt;
&lt;SPAN&gt;Next&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:19:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-code-for-view-labelling/m-p/10816698#M42479</guid>
      <dc:creator>rankinkane</dc:creator>
      <dc:date>2021-12-11T20:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: ilogic code for view labelling</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-code-for-view-labelling/m-p/10819420#M42480</link>
      <description>&lt;P&gt;I added your PartList/Item number portion of the posted code to the "FindAssemblyItemNumber" Function of my original post.&amp;nbsp; See complete code below:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;'Anything Outside The 'main' routine only runs when called
Sub Main
	'Try to set Active Document to a DrawingDocument Object
	Dim dDoc As DrawingDocument = TryCast(ThisApplication.ActiveDocument, DrawingDocument) 'This Fails to Nothing
	If IsNothing(dDoc) Then Logger.Debug("Not A DrawingDocuemnt") : Exit Sub
	'We know we have a drawing document open
	'Get User to select a view
	Dim PickView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a View")
	If IsNothing(PickView) Then Exit Sub 'If nothing gets selected then we're done
	'We now have a drawing view
	'Call routine for the selected view.
	Call ViewInfo(PickView)
	'Breaking up code like this helps for multipurposing.
	'If you want you can loop through all the views on a sheet
End Sub

'Sub Routine: Processes Custom Options for a given DrawingView Object
Sub ViewInfo(dView As DrawingView)
	'Define some Objects
	Dim ModelDoc As Document = dView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim ItemNumber As String 'I will need more information to make this work
	Dim mPartNumber As String 'ModelDocument PartNumber
	Dim smThickness As String 'SheetMetal Thickness As a number 
	Dim mMaterial As String 'ModelDocument Material

	'Try to set the model document to a PartDocument Object
	Dim pDoc As PartDocument = TryCast(ModelDoc, PartDocument)
	If Not IsNothing(pDoc) 'As long as it is anything/not nothing
		ItemNumber = FindAssemblyItemNumber(pDoc, dView.Parent.Parent) 'Call Custom Function to get Item Number
		mPartNumber = pDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value 'Get PartNumber iProperty
		smThickness = GetSheetMetalThickness(pDoc) 'Call Custom Function to get Sheet Metal Thickness [I'm going to return mm]
		mMaterial = pDoc.ActiveMaterial.DisplayName
		'Now I am sending the gathered information to the drawingview label.
		'If you want to put it somehwere else, let me know
		Call SetLabel(dView, ItemNumber, mPartNumber, smThickness, mMaterial) 'Custom Sub Routine
	End If
	
End Sub

'Sub Routine: Sets the DrawingView Label to a custom string format, centered &amp;amp; bottom of view for a given DrawingView Object
Sub SetLabel(dView As DrawingView, s1 As String, s2 As String, s3 As String, s4 As String)
	Dim ThisSheet As Sheet = dView.Parent 'Get The Sheet the view is on
	'Set Text to dsiplay
	Dim FormattedText As String = "&amp;lt;StyleOverride Underline='True'&amp;gt;" &amp;amp; s1 &amp;amp; " - " &amp;amp; s2 &amp;amp; "&amp;lt;/StyleOverride&amp;gt;&amp;lt;Br/&amp;gt;" &amp;amp; s3 &amp;amp; s4 
	'SetThe DrawingView Label &amp;amp; make sure it is visible &amp;amp; @ Bottom Center
	dView.ShowLabel = True
	Dim dvLabel As DrawingViewLabel = dView.Label
	dvLabel.FormattedText = FormattedText
	dvLabel.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
	dvLabel.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextLower
End Sub

'A Function sends something back after being called. It gets defined like any other Object
'Function: Return {AS String} Item number of given part document in Assembly. {assembly currently unknown}
Function FindAssemblyItemNumber(pDoc As PartDocument, oDrawDoc As DrawingDocument) As String
	Dim Result As String = "Assembly Info Not Found" 'Defualt Result
	
	Dim oPartList As PartsList
    'try and get the parts list form the table of this sheet
    Try
        oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
    Catch 'on error try and search all sheets for first found parts list           
        'iterate trough each sheet
        Dim i As Long
        For i = 1 To oDrawDoc.Sheets.Count
            If oDrawDoc.Sheets.Item(i).PartsLists.Count &amp;gt; 0 
				oPartList = oDrawDoc.Sheets.Item(i).PartsLists.Item(1)
				Exit For
			End If
        Next   
        'MessageBox.Show("parts list found on: " &amp;amp; i, "Title")
    End Try
      
	If IsNothing(oPartList) Then Logger.Debug("No PartsList found in drawing document") : Return Result
	
    ' Iterate through the contents of the parts list.
    Dim j As Long
    For j = 1 To oPartList.PartsListRows.Count
        ' Get the current row.
        Dim oRow As PartsListRow = oPartList.PartsListRows.Item(j)
        'get filename of model in row
        Dim oRowFileName As String = oRow.ReferencedFiles.Item(1).FullFileName
        'compare the filenames
        'Performs a text comparison, based on a case-insensitive text sort order
        'If strings equal returns 0
        If StrComp(pDoc.FullFileName, oRowFileName, CompareMethod.Text)=0
            'Get the value of Item from the Parts List
            'Row name needs to be case sensitive or use 1 for first 2 for second etc.
            oCell  = oPartList.PartsListRows.Item(j).Item("Item") 'Row name needs to be case sensitive or use 1 for first 2 for second etc.
            'get the value of text in cell
            Result = oCell.Value
			Return Result
		End If
	Next
	Return Result
End Function

'Function: Return {AS String} SheetMetal Thickness for given PartDocument Object
Function GetSheetMetalThickness(pDoc As PartDocument) As String
	Dim Result As String = "" 'Defualt Result
	Dim ResultValue As Double 'Set Object For Double Handling
	
	'Try to set a SheetMetalComponentDefinition Object
	Dim smDef As SheetMetalComponentDefinition = TryCast(pDoc.ComponentDefinition, SheetMetalComponentDefinition)
	If IsNothing(smDef) Then Return Result 'If The PartDocument is not a sheetmetal part return our 'nothing' default
		
	'We know we have a view of a sheetmetal Part and can call Specific Properties and methods
	ResultValue = smDef.Thickness.Value 'Database units for Length is cm. We have to convert to our desired unit type
	ResultValue *= 10 'I'm converting the value from cm to mm by multiplying itself by 10
	'I'm going to return mm with 3 decimals
	Result = Math.Round(ResultValue, 3).ToString &amp;amp; " mm "
	
	Return Result
End Function&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I changed the PartsList Try/Catch so it doesn't error out if no PartsList exists in the drawing, but left the rest of the formatting as you wrote it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if you have any questions, or if this is not working as intended.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Dec 2021 13:28:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-code-for-view-labelling/m-p/10819420#M42480</guid>
      <dc:creator>J-Camper</dc:creator>
      <dc:date>2021-12-13T13:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: ilogic code for view labelling</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-code-for-view-labelling/m-p/10826066#M42481</link>
      <description>&lt;P&gt;Thanks very much for that. It works great.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just need to add The text "ITEM NUMBER" before the item number itself but I will try and work that one out myself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Dec 2021 01:40:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-code-for-view-labelling/m-p/10826066#M42481</guid>
      <dc:creator>rankinkane</dc:creator>
      <dc:date>2021-12-16T01:40:40Z</dc:date>
    </item>
  </channel>
</rss>

