Select Specific Part file Within an Assembly Drawing, Change all Edges to a Specific Layer

Select Specific Part file Within an Assembly Drawing, Change all Edges to a Specific Layer

C_Haines_ENG
Collaborator Collaborator
496 Views
5 Replies
Message 1 of 6

Select Specific Part file Within an Assembly Drawing, Change all Edges to a Specific Layer

C_Haines_ENG
Collaborator
Collaborator

This is by far the most complicated thing I am trying to do, but its annoyingly the most important.

 

I have created a part file with multiple named solidbodies, I place this part inside the assembly to represent multiple door pull options. I need to be able to go through all active views, select the edges of the named solidbodies of the inserted part, and switch their layer.

 

Not entirely sure if this is possible but it would save me eons of time.

0 Likes
Accepted solutions (1)
497 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @C_Haines_ENG.  In this other recent post, is an example of selecting a DrawingCurveSegment from within a DrawingView using the Pick function, then digging into both the view, and into the model side of things based on that selection.  There have been several other similar examples like this around the forum too, which may be helpful.  Once you navigate to the assembly component you want, you can use the DrawingView.DrawingCurves(oInputModelObject) to get the DrawingCurvesEnumerator collection which represents the geometry for that input model object within that view.

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/retreive-part-information-from-drawi... 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

Andrii_Humeniuk
Advisor
Advisor

Hi @C_Haines_ENG . I have a rule that looks for phantom components and changes their edges. You need to customize the code in lines 17-27.

Sub main
	Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oTM As TransactionManager = ThisApplication.TransactionManager
	Dim newTM As Transaction = oTM.StartTransaction(oDDoc, "ChangeCurvesColor")
	For Each oSheet As Sheet In oDDoc.Sheets
		For Each oView As DrawingView In oSheet.DrawingViews
			Dim oRefDoc As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
			Dim oRefDef As AssemblyComponentDefinition = oRefDoc.ComponentDefinition
			Call ChangeCurvesView(oView, oRefDef.Occurrences)
		Next
	Next
	newTM.End()
End Sub

Private Function ChangeCurvesView(ByVal oView As DrawingView, ByVal oOccs As ComponentOccurrences)
	For Each oOcc As ComponentOccurrence In oOccs
		If oOcc.BOMStructure = BOMStructureEnum.kPhantomBOMStructure
			Dim oCurves As DrawingCurvesEnumerator = oView.DrawingCurves(oOcc)
			For Each oCurve As DrawingCurve In oCurves
				Try
					oCurve.Color = ThisApplication.TransientObjects.CreateColor(255, 0, 255) 'Pink
					oCurve.LineWeight = 0.018
				Catch
				End Try
			Next
			Continue For
		End If
		If oOcc.SubOccurrences IsNot Nothing Then
			Call ChangeCurvesView(oView, oOcc.SubOccurrences)
		End If
	Next
End Function

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 4 of 6

C_Haines_ENG
Collaborator
Collaborator

I cannot figure out why I cant apply a layer, I see in other applciations it requires a "DrawingCurveSegment", instead of Enumerator. 

Sub main
	Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oTM As TransactionManager = ThisApplication.TransactionManager
	Dim newTM As Transaction = oTM.StartTransaction(oDDoc, "ChangeCurvesColor")
	Dim oSB As SurfaceBody
	For Each oSheet As Sheet In oDDoc.Sheets
		For Each oView As DrawingView In oSheet.DrawingViews
			Dim oRefDoc As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
			Dim oRefDef As AssemblyComponentDefinition = oRefDoc.ComponentDefinition
			Call ChangeCurvesView(oView, oRefDef.Occurrences)
		Next
	Next
	newTM.End()
End Sub

Private Function ChangeCurvesView(ByVal oView As DrawingView, ByVal oOccs As ComponentOccurrences)
	
	Dim oDrawingDoc As DrawingDocument = ThisApplication.ActiveDocument

	For Each oOcc As ComponentOccurrence In oOccs

		If oOcc.Name.Contains("TEST PART")
			For Each oSB In oOcc.SurfaceBodies
				If oSB.Name = "NOVA"

					Dim oCurves As DrawingCurvesEnumerator = oView.DrawingCurves(oSB)
					For Each oCurve As DrawingCurve In oCurves
						Try
							oCurve.Layer = oDrawingDoc.StylesManager.Layers.Item("NOVA")
						Catch
						End Try
					Next
					Continue For
				End If
				Next
			End If
				If oOcc.SubOccurrences IsNot Nothing Then
					Call ChangeCurvesView(oView, oOcc.SubOccurrences)
				End If
			Next
End Function
0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor

That is because you must have another loop of the DrawingCurveSegments within each DrawingCurve, then the DrawingCurveSegment object has that Layer property.  Or you could collect all of the DrawingCurveSegments into an ObjectCollection and use the Sheet.ChangeLayer method to do them all at once.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

A layer can be accessed like this: oCurve.Segments.Item(1).Layer. Changed your code a bit, check if it works.

 

Sub main
	Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oTM As TransactionManager = ThisApplication.TransactionManager
	Dim newLayer As Layer = oDDoc.StylesManager.Layers.Item("NOVA")
	Dim newTM As Transaction = oTM.StartTransaction(oDDoc, "ChangeCurvesColor")
	Dim oSB As SurfaceBody
	For Each oSheet As Sheet In oDDoc.Sheets
		For Each oView As DrawingView In oSheet.DrawingViews
			Dim oRefDoc As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
			Dim oRefDef As AssemblyComponentDefinition = oRefDoc.ComponentDefinition
			Call ChangeCurvesView(oView, oRefDef.Occurrences, newLayer)
		Next
	Next
	newTM.End()
End Sub

Private Function ChangeCurvesView(ByVal oView As DrawingView, ByVal oOccs As ComponentOccurrences, ByVal newLayer As Layer)
	For Each oOcc As ComponentOccurrence In oOccs
		If oOcc.Name.Contains("TEST PART") Then
			For Each oSB As SurfaceBody In oOcc.SurfaceBodies
				If oSB.Name = "NOVA" Then
					Dim oCurves As DrawingCurvesEnumerator = oView.DrawingCurves(oSB)
					For Each oCurve As DrawingCurve In oCurves
						Try
							oCurve.Segments.Item(1).Layer = newLayer
						Catch
						End Try
					Next
					Continue For
				End If
			Next
		End If
		If oOcc.SubOccurrences IsNot Nothing Then
			Call ChangeCurvesView(oView, oOcc.SubOccurrences, newLayer)
		End If
	Next
End Function

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes