To check if part exists in drawing view

To check if part exists in drawing view

dialunau
Advocate Advocate
762 Views
3 Replies
Message 1 of 4

To check if part exists in drawing view

dialunau
Advocate
Advocate

Hello everyone

I'm looking for ways to know if a part that is inside an assembly exists in a drawing view using its name and if it does, highlight it. So far I've only found ways to get to the part from the view but not the other way around.

Does anyone know how to achieve this?

 

So far I can make sure the part exists in the assembly, but I need to highlight all the drawing curves that represent that part inside the view. My code looks like this:

 

Sub Main()
	Dim s As String = "A200"
Dim oView As DrawingView = oSheet.DrawingViews.Item(2) Dim oAssy As AssemblyDocument = oView.DrawingCurves.Item(1).Parent.ReferencedDocumentDescriptor.ReferencedDocument Dim oCDef As AssemblyComponentDefinition = oAssy.ComponentDefinition Dim oOcc As ComponentOccurrence For Each oOcc In oCDef.Occurrences If Left(oOcc.Name, oOcc.Name.Length - 2) = s Then 'Delete the ":1",":2",etc. Exit For 'Now I know it exists in the assembly End If Next oOcc End Sub

 

0 Likes
Accepted solutions (1)
763 Views
3 Replies
Replies (3)
Message 2 of 4

SevInventor
Advocate
Advocate
Accepted solution

Hello Dialunau,

 

find and highlight the drawing curves of an Occurrence is part of the following code posted here:

 

https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/highlight-not-ballooned-part-assembly-o...

 

hope that helps.

 

Sub Main()

	Dim oDoc As Document = ThisDoc.Document
    If oDoc.DocumentType <> kDrawingDocumentObject Then: MsgBox("Run in drawings only!"): Exit Sub: End If
        
	Dim oSheet As Sheet = oDoc.ActiveSheet
    If oSheet Is Nothing Then: MsgBox("Only valid for dwg files with sheets!"): Exit Sub: End If
	
    If oSheet.PartsLists.Count <> 1 Then: MsgBox("Only valid for sheets with 1 PartsList"):Exit Sub: End If
	Dim oPL As PartsList = oSheet.PartsLists(1)
	
    If oPL.PartsListRows.Count < 1 Then: MsgBox("Only valid for partslists with actual rows"): Exit Sub: End If
	If oSheet.Balloons.Count < 1 Then : MsgBox("Rule only valid for sheets with balloons!") : Exit Sub : End If
	Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument.ReferencedDocuments.Item(1)	
	Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
	Dim oview As DrawingView=oDoc.ActiveSheet.DrawingViews.item(2)	

	Dim oDoc1 As Document	
	Dim oSet As HighlightSet
	oSet = oDoc.CreateHighlightSet
   oview = ThisApplication.CommandManager _
        .Pick(kDrawingViewFilter, "Select a drawing view.")

	

	Dim Oocc As ComponentOccurrence
 		For Each oRow In oPL.PartsListRows
	 		If oRow.Ballooned = False Then

			oDoc1 = oRow.ReferencedFiles.Item(1).ReferencedDocument

					For Each Oocc In oAsmDef.Occurrences.AllReferencedOccurrences(oDoc1)
						Dim oCurveUnum As DrawingCurvesEnumerator
       					oCurveUnum = oview.DrawingCurves(Oocc)
        
        				Dim oCurve As DrawingCurve
        				Dim oSegment As DrawingCurveSegment
        
        					'add segments to collection to be moved to required layer
        				For Each oCurve In oCurveUnum
          					For Each oSegment In oCurve.Segments

						Try
							oSet.AddItem(oSegment)
							


Catch
	Continue For
End Try


					Next
					Next
					Next
			End If
		Next



Dim oColor As Color
oColor = ThisApplication.TransientObjects.CreateColor(0, 0, 255)

oSet.Color = oColor

MsgBox("ok?")

oSet.Clear()
End Sub

 

Message 3 of 4

dialunau
Advocate
Advocate

Perfect, that's exactly what I was looking for, now I can relate each component to the drawing curves representing them.

Thanks a lot.

0 Likes
Message 4 of 4

SevInventor
Advocate
Advocate

You're welcome, That was my first solution and kudos. Thanks for that!😁