Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Trouble getting components occurrences from assembly pattern using iLogic

sohaib.as01
Advocate
Advocate

Trouble getting components occurrences from assembly pattern using iLogic

sohaib.as01
Advocate
Advocate

Hello Everyone, hope you are all having a great day.

I am having trouble getting component occurrences for my drawing view, by using this I would like to place dimensions between the two named faces of the components.

Can someone please look at the code and let me know whats wrong with it? This code with some minor changing is working fine for other set of occurances which are at first level of a Component pattern, while these components named"overmoulded part" and "LED tape section" are at first and second level of pattern respectively, so I am wondering if thats the problem?

Attaching feature tree picture to clarify what I mean by above.

 

'Creating LED position dimension logic for View "A" and "A'" which are the section views
'Deleting iLogic created dimension to avoid creation of multiple dimensions at each update
Dim oDoc2 As Inventor.Document
oDoc2 = ThisApplication.ActiveDocument
ActiveSheet = ThisDrawing.Sheet("Sheet:1")
Dim oSheet As Sheet
oSheet = oDoc2.ActiveSheet
Dim oDim1 As GeneralDimension
For Each oDim1 In oSheet.DrawingDimensions
	If oDim1.AttributeSets.NameIsUsed("iLogic_Created") = True Then
		oDim1.Delete
	End If
	Next

For Each drwView2 As DrawingView In oSheet.DrawingViews
	If drwView2.Name = "A" Or drwView2.Name = "A'"
		oViewSec = drwView2
		Exit For
	End If
Next
'Exit if view can't be found
If oViewSec Is Nothing
	MsgBox("Couldn't find the drawing view named A or A'")
	MsgBox(oViewSec.Name)
	Exit Sub
End If


'Get the assembly document from the view
Dim oAsm As AssemblyDocument = oViewSec.ReferencedDocumentDescriptor.ReferencedDocument
Dim oCompDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
Dim oOcc1 As ComponentOccurrence
Dim oOcc2 As ComponentOccurrence
'Get the occurrence named overmoulded part:1 and LED tape section:1
'If Parameter("Lightsheet assembly.iam.LED_edge_qty") = 2
	Try
	oOcc1 = oCompDef.Occurrences.ItemByName("overmoulded part:1")
	oOcc2 = oCompDef.Occurrences.ItemByName("LED tape section:1")
	Catch
	MessageBox.Show(oOcc1.Name)
	MessageBox.Show(oOcc2.Name)

	'Exit if the occurrence can't be found
	Exit Sub
	End Try
	MsgBox("Couldn't find occurrences")
	'Get the named entities for both occurances
	Dim namedEntities1 = iLogicVb.Automation.GetNamedEntities(oOcc1.Definition.Document)
	Dim namedEntities2 = iLogicVb.Automation.GetNamedEntities(oOcc2.Definition.Document)
	Dim S1Face As Face
	Dim S2Face As Face
				MessageBox.Show("Here", "Error")

	'Get the face named J_Face
	Try
	S1Face = namedEntities1.FindEntity("Outer Face")
	S2Face = namedEntities2.FindEntity("Face 1")
	Catch
	'Exit if face cant be found
	MsgBox("Couldn't find the faces to place dimension on")
	End Try
	'Create a proxy object for the face
	Dim S1FaceProx As FaceProxy
	Dim S2FaceProx As FaceProxy
	oOcc1.CreateGeometryProxy(S1Face, S1FaceProx)
	oOcc2.CreateGeometryProxy(S1Face, S2FaceProx)
	'Create geometry intent for the first drawingcurve segment of the curve representing the face.
	Dim oIntent1 As GeometryIntent = oSheet.CreateGeometryIntent(oViewSec.DrawingCurves(S1FaceProx)(1))
	Dim oIntent2 As GeometryIntent = oSheet.CreateGeometryIntent(oViewSec.DrawingCurves(S2FaceProx)(1))

	'Create a Point2d for the dimensions text position
	Dim oText As Point2d = ThisApplication.TransientGeometry.CreatePoint2d _
	(oViewSec.Center.X + oViewSec.Width / 2 , oViewSec.Center.Y - oViewSec.Height / 2 - 1)
	'Add the dimension

	Dim oDim2 As LinearGeneralDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oText, oIntent1, oIntent2)
	'Center the text
	oDim2.CenterText

	'Add the attribute set to recognize that the dimension is placed by iLogic
	oDim2.AttributeSets.Add("iLogic_Created")

 

0 Likes
Reply
844 Views
7 Replies
Replies (7)

dutt.thakar
Collaborator
Collaborator

@sohaib.as01 

 

I have tried modifying your code a bit at the first glance without any actual testing, see if this helps.

 

'Creating LED position dimension logic for View "A" and "A'" which are the section views
'Deleting iLogic created dimension to avoid creation of multiple dimensions at each update
Dim oDoc2 As Inventor.Document
oDoc2 = ThisApplication.ActiveDocument
ActiveSheet = ThisDrawing.Sheet("Sheet:1")
Dim oSheet As Sheet
oSheet = oDoc2.ActiveSheet
Dim oDim1 As GeneralDimension
For Each oDim1 In oSheet.DrawingDimensions
	If oDim1.AttributeSets.NameIsUsed("iLogic_Created") = True Then
		oDim1.Delete
	End If
	Next
Dim oViewSec As DrawingView ' It is always good to define this
For Each drwView2 As DrawingView In oSheet.DrawingViews
	If drwView2.Name = "A" Or drwView2.Name = "A'"
		oViewSec = drwView2
		Exit For
	End If
Next
'Exit if view can't be found
If oViewSec Is Nothing
	MsgBox("Couldn't find the drawing view named A or A'")
	MsgBox(oViewSec.Name)
	Exit Sub
End If

'Get the assembly document from the view
Dim oAsm As AssemblyDocument = oViewSec.ReferencedDocumentDescriptor.ReferencedDocument
Dim oCompDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
Dim oOcc1 As ComponentOccurrence
Dim oOcc2 As ComponentOccurrence
''Get the occurrence named overmoulded part:1 and LED tape section:1
''If Parameter("Lightsheet assembly.iam.LED_edge_qty") = 2
	Try
	oOcc1 = oCompDef.Occurrences.ItemByName("overmoulded part:1")
	oOcc2 = oCompDef.Occurrences.ItemByName("LED tape section:1")
	Catch
	MessageBox.Show(oOcc1.Name)
	MessageBox.Show(oOcc2.Name)

	'Exit if the occurrence can't be found
	Exit Sub
	End Try
	'MsgBox("Couldn't find occurrences")
	
	
	'=========
	
	
	'Get the named entities for both occurances
	Dim namedEntities1 = iLogicVb.Automation.GetNamedEntities(oOcc1.Definition.Document)
	Dim namedEntities2 = iLogicVb.Automation.GetNamedEntities(oOcc2.Definition.Document)
	Dim S1Face As Face
	Dim S2Face As Face

'	'Get the face named J_Face
	Try
	S1Face = namedEntities1.FindEntity("Outer Face")
	S2Face = namedEntities2.FindEntity("Face 1")
	Catch
	'Exit if face cant be found
	MsgBox("Couldn't find the faces to place dimension on")
	End Try
	'Create a proxy object for the face
	Dim S1FaceProx As FaceProxy
	oOcc1.CreateGeometryProxy(S1Face, S1FaceProx)
	Dim S2FaceProx As FaceProxy 
	oOcc2.CreateGeometryProxy(S2Face, S2FaceProx) ' This was S1Face, so not able to create proxy
	
	Dim oDrawCurves As DrawingCurvesEnumerator = oViewSec.DrawingCurves(S1FaceProx)
	Dim oDC1 As DrawingCurve = oDrawCurves.Item(1)
	oDrawCurves = oViewSec.DrawingCurves(S2FaceProx)
	Dim oDC2 As DrawingCurve =  oDrawCurves.Item(1)
	
	'Create geometry intent for the first drawingcurve segment of the curve representing the face.
	Dim oIntent1 As GeometryIntent = oSheet.CreateGeometryIntent(oDC1)
	Dim oIntent2 As GeometryIntent = oSheet.CreateGeometryIntent(oDC2)

'	'Create a Point2d for the dimensions text position
	Dim oText As Point2d = ThisApplication.TransientGeometry.CreatePoint2d _
	(oViewSec.Center.X + oViewSec.Width / 2 , oViewSec.Center.Y - oViewSec.Height / 2 - 1)
	'Add the dimension

	Dim oDim2 As LinearGeneralDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oText, oIntent1, oIntent2)
	'Center the text
	oDim2.CenterText

	'Add the attribute set to recognize that the dimension is placed by iLogic
	oDim2.AttributeSets.Add("iLogic_Created")

 

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes

sohaib.as01
Advocate
Advocate

thanks for your reply @dutt.thakar 

No luck with the code. Throwing error, the SS attached hereby with error type and detail 😞

The error is occuring after this line

	Try
	oOcc1 = oCompDef.Occurrences.ItemByName("overmoulded part:1")
	oOcc2 = oCompDef.Occurrences.ItemByName("LED tape section:1")
	Catch

I am sure about the component occurrences name are correct and this same piece of code with just the difference in name of components is working fine for another component within the same assembly.

0 Likes

dutt.thakar
Collaborator
Collaborator

@sohaib.as01 

 

Can you attach your assembly here as a ZIP file if that's okay?

 

If you are not allowed to share your assembly, try recreating a small dataset with the same parts, run your code first if it gives the same error, please attach.

 

I will be able to look into it in more detail if I get it.

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes

sohaib.as01
Advocate
Advocate

Yes Sure, here are the files attached. 

I had to remove the title blocks but I guess that shouldn't cause any problems. Apart from that everything is as is.

Thank you so very much for your help Sir.

0 Likes

sohaib.as01
Advocate
Advocate

Sorry i forgot to mention, look for the rule I am struggling with in Lightstick Assembly drawing.idw having the name "Placing Dims".

0 Likes

sohaib.as01
Advocate
Advocate

Any luck with it @dutt.thakar ?

0 Likes

dutt.thakar
Collaborator
Collaborator

@sohaib.as01 

 

I tested with your drawing and the code I initially posted, It is capturing occurrences (that is already sorted), but not able to generate the dimension, It is capturing everything, including named entities and proxies but, just giving an error in the last line, when it has to add the dimension.

 

Error.PNG

 

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes