Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.
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")
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")
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.
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.
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.
Sorry i forgot to mention, look for the rule I am struggling with in Lightstick Assembly drawing.idw having the name "Placing Dims".
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.
Can't find what you're looking for? Ask the community or share your knowledge.