<?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: How se drawCurve color to ByLayer in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-se-drawcurve-color-to-bylayer/m-p/12411647#M160914</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/11986375"&gt;@Leonardo_Czuy&lt;/a&gt;.&amp;nbsp; Most of that code looks OK, but this is obviously not the entire code, so there are some things we can not know about this.&amp;nbsp; This Sub routine only has one input parameter, yet it is using several variables within it (such as MainLayer, drawCurves, &amp;amp; HiddenLayer) that are neither passed into it, nor created within it, so we don't know if those other variables have been declared, if they have been assigned values, or what Type of object they represent.&amp;nbsp; There is an odd couple of lines were you create a variable (oColor) for a Color object, do not set a value to it, then set that oColor variable as the value of 'drawCurve.Color.&amp;nbsp; I am not sure what you were trying to do there, but it does not look correct right now.&amp;nbsp; I assume that the 'drawCurves' variable represents a &lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-DrawingCurvesEnumerator" target="_blank" rel="noopener"&gt;DrawingCurvesEnumberator&lt;/A&gt;, and that the 'MainLayer' &amp;amp; 'HiddenLayer' variables represent &lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-Layer" target="_blank" rel="noopener"&gt;Layer&lt;/A&gt; objects, but if those variables are not declared at a 'higher level' within the overall code, then I do not know if this Sub routine will recognize them, or be able to use that as you intended.&amp;nbsp; Also, if those Layers are Layers exist within the drawing being currently processed or not.&amp;nbsp; If not, you may need to either copy those layers from a library to the drawing document, or create those layers within the drawing document directly, before you can use them.&lt;/P&gt;</description>
    <pubDate>Thu, 30 Nov 2023 19:33:58 GMT</pubDate>
    <dc:creator>WCrihfield</dc:creator>
    <dc:date>2023-11-30T19:33:58Z</dc:date>
    <item>
      <title>How se drawCurve color to ByLayer</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-se-drawcurve-color-to-bylayer/m-p/12411508#M160912</link>
      <description>&lt;P&gt;How to se DrawCurve to ByLayer?&lt;/P&gt;&lt;LI-CODE lang="general"&gt;	Sub SetDrawingCurvesLayer(ByVal app As Inventor.Application)
	    If (MainLayer Is Nothing) Then Return
	    If (drawCurves Is Nothing) Then Return
	
	    ' Create empty collections for curves on different layers
	    Dim objColl As ObjectCollection = app.TransientObjects.CreateObjectCollection()
	    Dim hiddenColl As ObjectCollection = Nothing
	    If (HiddenLayer IsNot Nothing) Then
	        hiddenColl = app.TransientObjects.CreateObjectCollection()
	    End If
	
	    ' Iterate through each drawing curve
	    For Each drawCurve As DrawingCurve In drawCurves
	        If (drawCurve.Segments Is Nothing) Then Continue For
				
			Dim oColor As Color
			
			drawCurve.Color = oColor
			
			
	        For Each segment As DrawingCurveSegment In drawCurve.Segments
	            If (segment.HiddenLine) Then
	                If (hiddenColl IsNot Nothing) Then
	                    hiddenColl.Add(segment)
	                End If
	            Else
	                ' Add the segment to the collection for visible curves
	                objColl.Add(segment)
	            End If
	        Next
	    Next
	
	    ' Change the layer of visible curves
	    If (objColl.Count &amp;gt; 0) Then
	        drawView.Parent.ChangeLayer(objColl, MainLayer)
	    End If
	
	    ' Change the layer of hidden curves
	    If (hiddenColl IsNot Nothing AndAlso hiddenColl.Count &amp;gt; 0) Then
	        drawView.Parent.ChangeLayer(hiddenColl, HiddenLayer)
	    End If
	End Sub&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 30 Nov 2023 18:22:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-se-drawcurve-color-to-bylayer/m-p/12411508#M160912</guid>
      <dc:creator>Leonardo_Czuy</dc:creator>
      <dc:date>2023-11-30T18:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: How se drawCurve color to ByLayer</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-se-drawcurve-color-to-bylayer/m-p/12411647#M160914</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/11986375"&gt;@Leonardo_Czuy&lt;/a&gt;.&amp;nbsp; Most of that code looks OK, but this is obviously not the entire code, so there are some things we can not know about this.&amp;nbsp; This Sub routine only has one input parameter, yet it is using several variables within it (such as MainLayer, drawCurves, &amp;amp; HiddenLayer) that are neither passed into it, nor created within it, so we don't know if those other variables have been declared, if they have been assigned values, or what Type of object they represent.&amp;nbsp; There is an odd couple of lines were you create a variable (oColor) for a Color object, do not set a value to it, then set that oColor variable as the value of 'drawCurve.Color.&amp;nbsp; I am not sure what you were trying to do there, but it does not look correct right now.&amp;nbsp; I assume that the 'drawCurves' variable represents a &lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-DrawingCurvesEnumerator" target="_blank" rel="noopener"&gt;DrawingCurvesEnumberator&lt;/A&gt;, and that the 'MainLayer' &amp;amp; 'HiddenLayer' variables represent &lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-Layer" target="_blank" rel="noopener"&gt;Layer&lt;/A&gt; objects, but if those variables are not declared at a 'higher level' within the overall code, then I do not know if this Sub routine will recognize them, or be able to use that as you intended.&amp;nbsp; Also, if those Layers are Layers exist within the drawing being currently processed or not.&amp;nbsp; If not, you may need to either copy those layers from a library to the drawing document, or create those layers within the drawing document directly, before you can use them.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2023 19:33:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-se-drawcurve-color-to-bylayer/m-p/12411647#M160914</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2023-11-30T19:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: How se drawCurve color to ByLayer</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-se-drawcurve-color-to-bylayer/m-p/12411655#M160915</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7812054"&gt;@WCrihfield&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Follow all code&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Sub Main
    drawDoc = TryCast(ThisDoc.Document, DrawingDocument)
	
    If (drawDoc Is Nothing) Then
       MessageBox.Show("Esta regra só pode ser executada em um desenho,", "iLogic")
       Return
    End If
	
	view = InputBox("Digite o Indentificador da Vista:", "iLogic")
	If view = "" Then
		MessageBox.Show("Necessário fornecer Indentificador da Vista", "iLogic")
		Return
	End If
	
	peca = InputBox("Digite o código da Peça:", "iLogic")
	If peca = "" Then
		MessageBox.Show("Necessário fornecer o código de uma peça", "iLogic")
		Return
	End If
	

    LookForView()
End Sub

Private drawDoc As DrawingDocument
Private modelDoc As Document
Private peca As String
Private view As String

Public Sub LookForView()
    ' Process the occurrences, wrapping it in a transaction so the 
    ' entire process can be undone with a single undo operation. 
    Dim trans As Transaction
    trans = ThisApplication.TransactionManager.StartTransaction(drawDoc, "Drawing Layers to Existing")

    Try
        For Each dSheet As Sheet In drawDoc.Sheets
            For Each drawView As DrawingView In dSheet.DrawingViews
                If (drawView.ViewType = DrawingViewTypeEnum.kDraftDrawingViewType) Then Continue For
                
				If drawView.Name.ToString() = view
		            Dim docDesc As DocumentDescriptor
		            docDesc = drawView.ReferencedDocumentDescriptor
					
					If (docDesc Is Nothing) Then Continue For
					If (docDesc.ReferencedDocumentType = DocumentTypeEnum.kAssemblyDocumentObject) Then
						If (docDesc.ReferencedDocument Is Nothing) Then Continue For
						Dim asmDef As AssemblyComponentDefinition
						Dim assemDoc As AssemblyDocument = TryCast(docDesc.ReferencedDocument, AssemblyDocument)
						If (assemDoc) Is Nothing Then Continue For
						asmDef = assemDoc.ComponentDefinition
						If (asmDef Is Nothing) Then Continue For
						If (asmDef.Occurrences Is Nothing) Then Continue For
						ProcessOccurrences(drawView, asmDef.Occurrences)
					ElseIf (docDesc.ReferencedDocumentType = DocumentTypeEnum.kPartDocumentObject) Then
						Dim partDoc As PartDocument = TryCast(docDesc.ReferencedDocument, PartDocument)
						If (partDoc Is Nothing) Then Continue For
							'ProcessPart(drawView, partDoc)
					End If
				End If		
            Next
        Next
    Catch
        trans.Abort()
		Return
    End Try
    trans.End()
End Sub

Sub ProcessOccurrences(ByVal drawView As DrawingView, ByVal Occurrences As ComponentOccurrences)
	' Iterate through the current collection of occurrences. 
	Dim occ As ComponentOccurrence
	For Each occ In Occurrences
		If (occ.Suppressed) Then Continue For
		If (occ.Definition Is Nothing) Then Continue For
		If (occ.ReferencedDocumentDescriptor Is Nothing) Then Continue For
		If (occ.ReferencedDocumentDescriptor.ReferenceMissing) Then Continue For
		
		Dim parentComponent As ComponentOccurrence = occ.ParentOccurrence
		Dim FileName As String
		
		If parentComponent IsNot Nothing
			FileName = parentComponent.Name
		    Dim partes As String() = FileName.Split(":"c)
		    FileName = partes(0).Trim()
		End If
		
		If occ.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
			' ** It's a part, so get the material.
			if FileName &amp;lt;&amp;gt; peca Then Continue For
			Dim partDoc As PartDocument = TryCast(occ.Definition.Document, PartDocument)
			If (partDoc Is Nothing) Then Continue For

			' Get all of the curves associated with this occurrence. 
			Dim drawCurves As DrawingCurvesEnumerator = Nothing
			Try
				drawCurves = drawView.DrawingCurves(occ)
			Catch
				drawCurves = Nothing
			End Try
			If (drawCurves IsNot Nothing) Then

				Dim matLayers As New MaterialLayers(drawDoc, partDoc, drawView, drawCurves)
				matLayers.GetOrCreateMainLayer()
				matLayers.SetDrawingCurvesLayer(ThisApplication)
			End If
		Else
			' It's an assembly, so process its contents. 
			Call ProcessOccurrences(drawView, occ.SubOccurrences)
		End If
	Next
End Sub

Class MaterialLayers
	Public MainLayer As Layer
	Public HiddenLayer As Layer

	' The layer for:
	' Solid lines in a plan or projected view:     MaterialName
	' Hidden lines in a plan or projected view:    MaterialName-Hidden
	' Solid lines in any other view:               MaterialName-View
	' Hidden lines in any other view:              MaterialName-View-Hidden

	Private drawDoc As DrawingDocument
	Private partDoc As PartDocument
	Private drawView As DrawingView
	Private drawCurves As DrawingCurvesEnumerator

	Public Sub New(ByRef drawDoc As DrawingDocument, ByVal partDoc As PartDocument, ByVal drawView As DrawingView, ByVal drawCurves As DrawingCurvesEnumerator)
		Me.drawDoc = drawDoc
		Me.partDoc = partDoc
		Me.drawView = drawView
		Me.drawCurves = drawCurves
	End Sub
	
	Sub GetOrCreateMainLayer()
		Dim layers As LayersEnumerator = drawDoc.StylesManager.Layers
		Try
			ContorniLayer = layers.Item("CONTORNI")
		Catch
		End Try
		
		Try
			NacosteLayer = layers.Item("NASCOSTE")
		Catch
		End Try
		MainLayer = ContorniLayer
		HiddenLayer = NacosteLayer
	End Sub
	
	Sub SetDrawingCurvesLayer(ByVal app As Inventor.Application)
	    If (MainLayer Is Nothing) Then Return
	    If (drawCurves Is Nothing) Then Return
	
	    ' Create empty collections for curves on different layers
	    Dim objColl As ObjectCollection = app.TransientObjects.CreateObjectCollection()
	    Dim hiddenColl As ObjectCollection = Nothing
	    If (HiddenLayer IsNot Nothing) Then
	        hiddenColl = app.TransientObjects.CreateObjectCollection()
	    End If
	
	    ' Iterate through each drawing curve
	    For Each drawCurve As DrawingCurve In drawCurves
	        If (drawCurve.Segments Is Nothing) Then Continue For
				
			drawCurve.Color = MainLayer.Color
			
	        For Each segment As DrawingCurveSegment In drawCurve.Segments
	            If (segment.HiddenLine) Then
	                If (hiddenColl IsNot Nothing) Then
	                    hiddenColl.Add(segment)
	                End If
	            Else
	                ' Add the segment to the collection for visible curves
	                objColl.Add(segment)
	            End If
	        Next
	    Next
	
	    ' Change the layer of visible curves
	    If (objColl.Count &amp;gt; 0) Then
	        drawView.Parent.ChangeLayer(objColl, MainLayer)
	    End If
	
	    ' Change the layer of hidden curves
	    If (hiddenColl IsNot Nothing AndAlso hiddenColl.Count &amp;gt; 0) Then
	        drawView.Parent.ChangeLayer(hiddenColl, HiddenLayer)
	    End If
	End Sub

End Class&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 30 Nov 2023 19:36:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-se-drawcurve-color-to-bylayer/m-p/12411655#M160915</guid>
      <dc:creator>Leonardo_Czuy</dc:creator>
      <dc:date>2023-11-30T19:36:48Z</dc:date>
    </item>
  </channel>
</rss>

