Hi,
I figured out how to create a drawing , place views and a section view by using iLogic (see attachement).
The next step is to create dimensions automatically by using iLogic.
I can't find a way how to create any dimension of the assembly in the drawing.
The only way I found is by using the attribute helper as seen in this video:
https://www.youtube.com/watch?v=bcOvYc6rNUk
But this requires an add in which I do not want to use because it has to work on different computers which don't always have the add in.
So my question is:
- How do I create a dimension in a drawing (by using iLogic)?
- Is it possible to create a dimension by using 2 planes in a assembly as reference points (by using iLogic)?
Solved! Go to Solution.
Solved by rikard.nilsson. Go to Solution.
Look at the API help from Inventor, there are some examples, like this one:
Sub CreateLinearForeshortenedDimSample() ' Open a drawing document and select two parallel linear curves in same drawing view first. Dim oApp As Inventor.Application Set oApp = ThisApplication Dim oDoc As Document Set oDoc = oApp.ActiveDocument If Not (oDoc Is Nothing) Then If Not (oDoc.DocumentType = kDrawingDocumentObject) Then MsgBox "Please activate a drawing document for this sample.", vbCritical, "Inventor" Exit Sub End If Else MsgBox "Please open a drawing document for this sample.", vbCritical, "Inventor" Exit Sub End If If Not (oDoc.SelectSet.Count = 2) Then MsgBox "Please select two parallel linear drawing curves from same drawing view for this sample.", vbCritical, "Inventor" Exit Sub ElseIf (oDoc.SelectSet(1).Type <> kDrawingCurveSegmentObject Or oDoc.SelectSet(1).Type <> kDrawingCurveSegmentObject) Then MsgBox "Please select two parallel linear drawing curves from same drawing view for this sample.", vbCritical, "Inventor" Exit Sub End If Dim oCurve1 As DrawingCurve, oCurve2 As DrawingCurve Set oCurve1 = oDoc.SelectSet(1).Parent Set oCurve2 = oDoc.SelectSet(2).Parent Dim oSheet As Sheet Set oSheet = oCurve1.Parent.Parent ' Create two GeometryIntent based on the selected drawing curve segments. Dim oIntent1 As GeometryIntent, oIntent2 As GeometryIntent Set oIntent1 = oSheet.CreateGeometryIntent(oCurve1) Set oIntent2 = oSheet.CreateGeometryIntent(oCurve2) Dim oTextPos As Point2d Set oTextPos = oApp.TransientGeometry.CreatePoint2d(12, 12) ' Create the linear foreshortened dimension Dim oLinearForeshortenedDim As LinearGeneralDimension Set oLinearForeshortenedDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinearForeshortened(oTextPos, oIntent1, oIntent2, True) End Sub
the attribute helper wil help you to select the right geometry to place the dimensions on.
(it wil not be easy)
@Anonymous wrote:
Hi,
My suggestion for you is to use named Work Pounts to use when you create the Geomert Intent.
I found this to be the easiest way and works both in assemblies and parts.
Regards
Rikard
Could you give me an example of this?
Hi,
Here is a pdf created by Autodesk
https://forums.autodesk.com/autodesk/attachments/autodesk/120/58687/1/MA316-5,ConfiguratorTips.pdf
On the last page(23) is a very simple example how to add a dimension between two workpoints..
And here is a code for finding a named work'point and create a Geometry Intent of that one..
SyntaxEditor Code Snippet
Private Function CreateWorkPointCenterMarksIfInTopLevel(entity1 As String, oSheet As Sheet, oView As DrawingView, oDoc As Inventor.Document) As Inventor.GeometryIntent Dim oWP1 As Inventor.WorkPoint oWP1 = oDoc.ComponentDefinition.WorkPoints.Item(entity1) Try oView.SetIncludeStatus(oWP1, True) Catch End Try Dim oCenterMark1 As Inventor.Centermark Dim oCenterMark As Inventor.Centermark For Each oCenterMark In oSheet.Centermarks If oCenterMark.Attached Then If oCenterMark.AttachedEntity Is oWP1 And ifCenterMarkIsInsideViewBorder(oCenterMark, oView) = True Then oCenterMark1 = oCenterMark End If End If Next Dim oGeomIntent1 As Inventor.GeometryIntent oGeomIntent1 = oSheet.CreateGeometryIntent(oCenterMark1, kPoint2dIntent) oCenterMark1.Visible = False Return oGeomIntent1 End Function
I'm going to try the pdf code in about 5 hours and I will place my results in this post.
Two questions before I start:
1. The "workpoints", that are referred to in the pdf, are those actual workpoints in the assembly? Assemble tab -> Workfeatures -> point
2. Will this code work in iLogic? It is a VBA code and i'm using iLogic only.
1) Yes they are.. That's why I added my code for finding the work point by name instead.. It's much easier that way..
2) For me when I read the code it's a iLogic-code. The only thing I would not add is all the ByVal in the arguments.. But I'm pretty sure that it will work with them also..
/Rikard
It took me a little longer before I could try out the code.
I just tried to use the code from the pdf to create centermarks but I'm getting an error at the start.
The code so far:
Dim oDrawDoc As DrawingDocument oDrawDoc = ThisDoc.Document Dim oSheet As Sheet oSheet = oDrawDoc.ActiveSheet Dim oView As DrawingView oView = ActiveSheet.View("View2").View Dim marks(1) As Centermark marks(0) = oSheet.Centermarks.AddByWorkFeature(WorkPoint1, oView) marks(0).Visible = True marks(1) = oSheet.Centermarks.AddByWorkFeature(WorkPoint2, oView) marks(1).Visible = True
The error:
Error in rule: Rule0, in document: Assembly1
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
Hi,
Here is how you add a vertical dimension to two named work points..
Just change the names of the points and the name of the view..
/Rikard
Sub AddLinearDimension() Dim oSheet As Sheet = ThisDoc.Document.ActiveSheet Dim oView As DrawingView = ActiveSheet.View("Test").View Dim oDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument Dim oGeomIntent1 As Inventor.GeometryIntent Dim oGeomIntent2 As Inventor.GeometryIntent Dim oWP1 As Inventor.WorkPoint = oDoc.ComponentDefinition.WorkPoints.Item("WP_1") Dim oWP2 As Inventor.WorkPoint = oDoc.ComponentDefinition.WorkPoints.Item("WP_2") oView.SetIncludeStatus(oWP1, True) oView.SetIncludeStatus(oWP2, True) Dim oCenterMark1 As Inventor.Centermark Dim oCenterMark2 As Inventor.Centermark Dim oCenterMark As Inventor.Centermark For Each oCenterMark In oSheet.Centermarks If oCenterMark.Attached Then If oCenterMark.AttachedEntity Is oWP1 Then oCenterMark1 = oCenterMark End If If oCenterMark.AttachedEntity Is oWP2 Then oCenterMark2 = oCenterMark End If End If Next oGeomIntent1 = oSheet.CreateGeometryIntent(oCenterMark1, kPoint2dIntent) oGeomIntent2 = oSheet.CreateGeometryIntent(oCenterMark2, kPoint2dIntent) oCenterMark1.Visible = False oCenterMark2.Visible = False Dim textPoint As Inventor.Point2d = ThisServer.TransientGeometry.CreatePoint2d(100,100) Dim oDim as GeneralDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(textPoint, oGeomIntent1, oGeomIntent2, DimensionTypeEnum.kVerticalDimensionType) End Sub
Works flawlessly.
Will try more stuff with workpoints later on.
Thanks for now!
Hello @rikard.nilsson
I tried to implementation your rule in my files. But I'm facing a problem, could you help me please?
Sub Main AddLinearDimension() Dim oSheet As Sheet = ThisDoc.Document.ActiveSheet Dim oView As DrawingView = ActiveSheet.View("VISTA1").View Dim oDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument Dim oGeomIntent1 As Inventor.GeometryIntent Dim oGeomIntent2 As Inventor.GeometryIntent Dim oGeomIntent3 As Inventor.GeometryIntent Dim oWP1 As Inventor.WorkPoint = oDoc.ComponentDefinition.WorkPoints.Item("WP_1") Dim oWP2 As Inventor.WorkPoint = oDoc.ComponentDefinition.WorkPoints.Item("WP_2") Dim oWP3 As Inventor.WorkPoint = oDoc.ComponentDefinition.WorkPoints.Item("WP_3") oView.SetIncludeStatus(oWP1, True) oView.SetIncludeStatus(oWP2, True) oView.SetIncludeStatus(oWP3, True) Dim oCenterMark1 As Inventor.Centermark Dim oCenterMark2 As Inventor.Centermark Dim oCenterMark3 As Inventor.Centermark Dim oCenterMark As Inventor.Centermark For Each oCenterMark In oSheet.Centermarks If oCenterMark.Attached Then If oCenterMark.AttachedEntity Is oWP1 Then oCenterMark1 = oCenterMark End If If oCenterMark.AttachedEntity Is oWP2 Then oCenterMark2 = oCenterMark End If If oCenterMark.AttachedEntity Is oWP3 Then oCenterMark3 = oCenterMark End If End If Next oGeomIntent1 = oSheet.CreateGeometryIntent(oCenterMark1, kPoint2dIntent) oGeomIntent2 = oSheet.CreateGeometryIntent(oCenterMark2, kPoint2dIntent) oGeomIntent3 = oSheet.CreateGeometryIntent(oCenterMark2, kPoint2dIntent) oCenterMark1.Visible = False oCenterMark2.Visible = False oCenterMark3.Visible = False 'Dimension Position Horizontal WP_1 - WP_2 Dim DimPosHor As Inventor.Point2d = ThisServer.TransientGeometry.CreatePoint2d(25,10) Dim oDimPosHor As GeneralDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(textPoint, oGeomIntent1, oGeomIntent2, DimensionTypeEnum.kHorizontalDimensionType) 'Dimension Position Vertical WP_2 - WP_3 Dim DimPosVer As Inventor.Point2d = ThisServer.TransientGeometry.CreatePoint2d(15,15) Dim oDimPosVer As GeneralDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(textPoint, oGeomIntent2, oGeomIntent3, DimensionTypeEnum.kVerticalDimensionType) End Sub
The dimensions not insert on drawing.
Hi,
In your Addlinear, you are using textPoint.. You have not declared that one and not set it to something..
GeneralDimensions.AddLinear(textPoint,.....
/Rikard
Ok, according to how I wrote the rule, I should use:
...
'Dimension Position Horizontal WP_1 - WP_2 Dim DimPosHor As Inventor.Point2d = ThisServer.TransientGeometry.CreatePoint2d(25,10) Dim oDimPosHor As GeneralDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(DimPosHor, oGeomIntent1, oGeomIntent2, DimensionTypeEnum.kHorizontalDimensionType) 'Dimension Position Vertical WP_2 - WP_3 Dim DimPosVer As Inventor.Point2d = ThisServer.TransientGeometry.CreatePoint2d(15,15) Dim oDimPosVer As GeneralDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(DimPosVer, oGeomIntent2, oGeomIntent3, DimensionTypeEnum.kVerticalDimensionType)
I tried to use it but the dimension is create just on horizontal and not vertical.
Hi,
If you look at your row with oGeomIntent3. You use oCenterMark2. It should be oCenterMark3..
oGeomIntent3 = oSheet.CreateGeometryIntent(oCenterMark3, kPoint2dIntent)
/Rikard
@Anonymous thank you for helping. The rule worked.
I have a question about dimension position. There is a method to find a coordination of the dimension and define a point default (x,y)?
For the example. If I use "ActiveSheet.View("VIEW1").SetCenter(centerX, centerY)" I'm able to set a view position. Therefore, there is a similar syntaxy to use with dimensions?
Hi,
The way usually solve this is actually by using view border. So if I want to place a dimension to the right.
Then I get the position by (View.center.X + view.width/2). Not the correct syntax but I hope you understand.
Then I place the dimension by setting it to Center so I don't have to take care of the Y-coordinate
/Rikard
I have found this very helpful.
Thank you.
Do you know of a way to centralize the displayed dimension midway between the referenced work points?
there is a method: "CenterText" that applies to LiniearGeneralDimension and AngularGeneralDimension.
so in you General dimensions, you have to filter these out (GeneralDimension.type)
This thread has helped me a ton with auto placing dimensions so my thanks to you guys. The problem is it only works when the Work Points are placed in the assembly itself. I have parts which will be removed through iLogic rules so I've placed the Work Points on the parts instead of in the assembly.
I was hoping it would give me the dimensions of only the parts enabled. Instead it just gives me the stupid error that my parameter is incorrect.
The error is in the following line:
Dim oWP1 As Inventor.WorkPoint = oDoc.ComponentDefinition.WorkPoints.Item("WPO-1")
Can't find what you're looking for? Ask the community or share your knowledge.