Trouble getting components occurrences from assembly pattern using iLogic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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")
Link copied