iLogic create dimension using named geometry in idw

iLogic create dimension using named geometry in idw

jdasilvaS39UQ
Advocate Advocate
3,692 Views
11 Replies
Message 1 of 12

iLogic create dimension using named geometry in idw

jdasilvaS39UQ
Advocate
Advocate

With the addition of named geometry, I thought it would be nice to be able to use named faces to create automatic dimensions in an idw, potentially as a cleaner or more robust alternative to using work points.

 

Below is some code I am having difficulty with, I am trying to get the drawing curve that corresponds to the named face, when looking at it in a side view and then dimension using the extents of the line as my dimension points, see attached screenshot. My end goal is to dimension a named face in a section view.

 

My curve0 count is returning 1 so it seems to be finding a drawing curve but I cannot generate a dimension of it.

i am getting an error on the last line when trying to create the actual dimension.

 

Is this possible to dimension to a face?

 

Dim partDoc As PartDocument = ThisDoc.ModelDocument
Dim namedEntities = iLogicVb.Automation.GetNamedEntities(partDoc)
Dim face0 As Face = namedEntities.FindEntity("Face0")

Dim oSheet = ThisDoc.Document.ActiveSheet

Dim oView As DrawingView = ActiveSheet.View("VIEW1").View

Dim curve0 As DrawingCurvesEnumerator

curve0 = oView.DrawingCurves(face0)

Dim finalCurve As DrawingCurve

MessageBox.Show(curve0.Count.ToString)

finalCurve = curve0.Item(1)

'MessageBox.Show(finalCurve.ToString)

Dim oGeomIntent1 As GeometryIntent
Dim oGeomIntent2 As GeometryIntent

oGeomIntent1 = oSheet.CreateGeometryIntent(finalCurve.StartPoint, kStartPointIntent)
oGeomIntent2 = oSheet.CreateGeometryIntent(finalCurve.EndPoint, kEndPointIntent)

Dim textPoint As Inventor.Point2d = ThisServer.TransientGeometry.CreatePoint2d(oView.Center.X,oView.Top)
'Error on this line below Dim oDim As GeneralDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(textPoint, oGeomIntent1, oGeomIntent2, DimensionTypeEnum.kHorizontalDimensionType

 

0 Likes
Accepted solutions (1)
3,693 Views
11 Replies
Replies (11)
Message 2 of 12

jdasilvaS39UQ
Advocate
Advocate
Accepted solution

I figured it out, I got rid of "As GeneralDimension" in the last line.

 

Working code if anyones interested

Dim partDoc As PartDocument = ThisDoc.ModelDocument
Dim namedEntities = iLogicVb.Automation.GetNamedEntities(partDoc)
Dim face0 As Face = namedEntities.FindEntity("Face0")
Dim face1 As Face = namedEntities.FindEntity("Face1")

Dim oSheet = ThisApplication.ActiveDocument.ActiveSheet

Dim oView As DrawingView = ActiveSheet.View("VIEW1").View

'Dim curve0 As DrawingCurvesEnumerator

curve0 = oView.DrawingCurves(face0)
curve1 = oView.DrawingCurves(face1)

Dim finalCurve As DrawingCurve
Dim finalCurve1 As DrawingCurve

MessageBox.Show(curve0.Count.ToString)

finalCurve = curve0.Item(1)
finalCurve1 = curve1.Item(1)

'MessageBox.Show(finalCurve.ToString)

Dim oGeomIntent1 As GeometryIntent
Dim oGeomIntent2 As GeometryIntent

Dim oGeneralDims As GeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions

oGeomIntent1 = oSheet.CreateGeometryIntent(finalCurve)
oGeomIntent2 = oSheet.CreateGeometryIntent(finalCurve.EndPoint)
'oGeomIntent1 = oSheet.CreateGeometryIntent(finalCurve)
'oGeomIntent2 = oSheet.CreateGeometryIntent(finalCurve1)
Dim textPoint As Inventor.Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oView.Center.X,oView.Top + .10)
'Error on this line below
oDim = oGeneralDims.AddLinear(textPoint, oGeomIntent1)
Message 3 of 12

Paul1084
Advocate
Advocate

Excellent! thanks for the code... I got this to work on an assembly document referencing named faces within assembly components by creating geometry proxy objects... for those that are interested code below for dimensioning off named faces in assembly components:

Dim Doc As DrawingDocument
Doc = ThisDoc.Document 

Dim oAsmDoc As AssemblyDocument
Dim oCompDef As AssemblyComponentDefinition

Dim FPColl As ObjectCollection
Dim OverallColl As ObjectCollection
Dim oText As Point2d

Dim S1 = oCompDef.Occurrences.ItemByName("SU1")
Dim S2 = oCompDef.Occurrences.ItemByName("SU2")

FPColl = ThisServer.TransientObjects.CreateObjectCollection
OverallColl = ThisServer.TransientObjects.CreateObjectCollection

Dim namedEntities = iLogicVb.Automation.GetNamedEntities(S1.Definition.Document)
Dim S1Face As Face = namedEntities.FindEntity("InsideFace")

Call S1.CreateGeometryProxy(S1Face, oSketchProxy)
Dim S1Curve = oView.DrawingCurves(oSketchProxy)

oIntent = oSheet.CreateGeometryIntent(S1Curve.Item(1))
Call OverallColl.Add(oIntent)

namedEntities = iLogicVb.Automation.GetNamedEntities(S2.Definition.Document)
Dim S2Face As Face = namedEntities.FindEntity("InsideFace")

Call S2.CreateGeometryProxy(S2Face, oSketchProxy)
Dim S2Curve = oView.DrawingCurves(oSketchProxy)

oIntent = oSheet.CreateGeometryIntent(S2Curve.Item(1))
Call OverallColl.Add(oIntent)

oText = ThisServer.TransientGeometry.CreatePoint2d(oView.Center.X - oView.Width / 2, oView.Center.Y - oView.Height / 2)

oText.Y = oText.Y - 1

Call oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oText, OverallColl.Item(1), OverallColl.Item(2)).CenterText
						
Message 4 of 12

jholland3XDLM
Advocate
Advocate

I am having trouble with this. 

oCompDef is not set to anything that I can see. Not sure how to point it at the Assembly in the drawing. Also, I need to drill down into a sub assembly before finally finding a part, with a named face.

0 Likes
Message 5 of 12

Paul1084
Advocate
Advocate

Sorry, set oAsmDoc as the assembly document you are referencing in the IDW:

 

oAsmDoc = Doc.ReferencedDocuments.Item(1) 

 

(If you have more than one referenced doc, then point to the correct one)

 

oCompDef (not well named, sorry... sloppy code) = oAsmDoc.Definition

 

To drill down through subassemblies, I think you will need to create more proxy objects for referencing each subassembly... if your having trouble, let me know, I will dig out some code where I have done this before

0 Likes
Message 6 of 12

jholland3XDLM
Advocate
Advocate

I've not dealt with proxy before. I don't actually know what that is. Inventor Help states that a proxy object represents another object within the assembly space.  So if I am drilling down into a sub-assembly, the proxy geometry would be the sub-assembly or the part's proxy? Sorry I am not really understanding this proxy stuff. I do know that up to that point the code seems to be working, so the oCompDef is solved. I created a second set of Assembly Document and Definition for the sub-assembly as well, with the wonderfully creative name oCompDef2. 

0 Likes
Message 7 of 12

Anonymous
Not applicable

Hi Paul1084

 

Thank you to all the guys who share there codes on these forums. Much appreciated. I am trying to learn as much as possible about ilogic code at the moment but its a slow process. Have been using ilogic for several years now and have created the occasional basic one myself.

I used the ilogic code shown above on an .iam in an .idw but am getting error messages with the code as per the attachment.  The first posted code in this thread is working on .ipt files in .idw but gives me a random dimension which is not even using the assigned faces as dimension points. Not sure what I'm doing wrong?

What I am trying to achieve is a few basic auto dimensions for a .idw with multiple views. Happy to use the Assign Face method but it would be awesome if an ilogic code could be made to place dims for certain parameters or User Parameters eg. B_L or G_L. This way the dims could be automatically created from CC parts. I have tried using the retrieve dims ilogic method before but that gives to many unwanted dimensions.

Appreciate any help. 

 

Cam

 

0 Likes
Message 8 of 12

jdasilvaS39UQ
Advocate
Advocate

From those errors, it looks like you aren't successfully getting a reference to your sheet or view. Did you change the name of your drawing views?

0 Likes
Message 9 of 12

Anonymous
Not applicable

Can you please send me the working code if possible.

I used code as above but getting this error: "Public member 'Definition' on type 'AssemblyDocument' not found"

rishabhshanker_1-1595965804354.png

 

Here is the code I am using. Please mark where i am wrong. Thanks in advance

Dim Doc As DrawingDocument
Doc = ThisDoc.Document 

Dim oSheet = ThisApplication.ActiveDocument.ActiveSheet

Dim oView As DrawingView = ActiveSheet.View("A").View

Dim oAsmDoc As AssemblyDocument
Dim oCompDef As AssemblyComponentDefinition

oAsmDoc = Doc.ReferencedDocuments.Item(1)

oCompDef = oAsmDoc.Definition  ----- ERROR as mentioned above

Dim FPColl As ObjectCollection
Dim OverallColl As ObjectCollection
Dim oText As Point2d

Dim S1 = oCompDef.Occurrences.ItemByName("Box") ----"Box" name of part in assembly
Dim S2 = oCompDef.Occurrences.ItemByName("Box2") ----"Box2" name of part in assembly
FPColl = ThisServer.TransientObjects.CreateObjectCollection
OverallColl = ThisServer.TransientObjects.CreateObjectCollection

Dim namedEntities = iLogicVb.Automation.GetNamedEntities(S1.Definition.Document)
Dim S1Face As Face = namedEntities.FindEntity("Box1Face")

Call S1.CreateGeometryProxy(S1Face, oSketchProxy)
Dim S1Curve = oView.DrawingCurves(oSketchProxy)

oIntent = oSheet.CreateGeometryIntent(S1Curve.Item(1))
Call OverallColl.Add(oIntent)

namedEntities = iLogicVb.Automation.GetNamedEntities(S2.Definition.Document)
Dim S2Face As Face = namedEntities.FindEntity("Box2Face")

Call S2.CreateGeometryProxy(S2Face, oSketchProxy)
Dim S2Curve = oView.DrawingCurves(oSketchProxy)

oIntent = oSheet.CreateGeometryIntent(S2Curve.Item(1))
Call OverallColl.Add(oIntent)

oText = ThisServer.TransientGeometry.CreatePoint2d(oView.Center.X - oView.Width / 2, oView.Center.Y - oView.Height / 2)

oText.Y = oText.Y - 1

Call oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oText, OverallColl.Item(1), OverallColl.Item(2)).CenterText

 

0 Likes
Message 10 of 12

sjoerd.van.der.eerden
Contributor
Contributor

hi, 

im relatively new to ilogic so I need some help. 

I want to add a balloon using ilogic and a named face as a reference. 

for this I use the standard balloon snippet. 

but the named reference face is two assemblys deep. so inventor wont accept the code shown below. (this does work for one assembly deep). so my question is can I create a proxy for the named face in the assembly above it. and then use the proxy in the balloon code. 

sjoerdvandereerden_0-1670324694265.png

inventor doesn't accept this

sjoerdvandereerden_1-1670324792206.png

but does accept this 

0 Likes
Message 11 of 12

jdasilvaS39UQ
Advocate
Advocate

I don't have any exact code but you can take what Paul1084 posted but then recursively search through each suboccurrence of your assembly. Here's a very rough outline

 

Sub Main

     Put your main code here 

     

Call this function to find your sub assembly/part with the named face

     SearchForSubassembly(mainassembly.occurrences)

End Sub

 

SearchForSubassembly(inputOccs As ComponentOccurrences)

    For Each oOcc In inputOccs

        Check if this is what you're looking for

        

         If not, keep searching

         SearchForSubassembly(oOcc.SubOccurrences)

    Next

End Sub

0 Likes
Message 12 of 12

sjoerd.van.der.eerden
Contributor
Contributor

it turned out my code was fine. the problem was that i was missing two brackets {}.😣

0 Likes