Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic create dimension in drawing

19 REPLIES 19
SOLVED
Reply
Message 1 of 20
Anonymous
10179 Views, 19 Replies

iLogic create dimension in drawing

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)?

19 REPLIES 19
Message 2 of 20
HermJan.Otterman
in reply to: Anonymous

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)

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 3 of 20
rikard.nilsson
in reply to: Anonymous

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
Message 4 of 20
Anonymous
in reply to: rikard.nilsson


@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?

Message 5 of 20
rikard.nilsson
in reply to: Anonymous

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 

 

Message 6 of 20
Anonymous
in reply to: rikard.nilsson

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.

Message 7 of 20
rikard.nilsson
in reply to: Anonymous

 

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

Message 8 of 20
Anonymous
in reply to: rikard.nilsson

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))

 

 

 

 

Message 9 of 20
rikard.nilsson
in reply to: Anonymous

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

 

Message 10 of 20
Anonymous
in reply to: rikard.nilsson

Works flawlessly.

 

Will try more stuff with workpoints later on.

Thanks for now!

Message 11 of 20
markGlthen
in reply to: rikard.nilsson

Hello @rikard.nilsson 

 

I tried to implementation your rule in my files. But I'm facing a problem, could you help me please?

WorkPointPosition.png

 

 

 

 

 

 

 

 

 

 

 

 

 

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. 

Message 12 of 20
rikard.nilsson
in reply to: markGlthen

Hi,

 

In your Addlinear, you are using textPoint.. You have not declared that one and not set it to something..

GeneralDimensions.AddLinear(textPoint,.....

 

 

 /Rikard

Message 13 of 20
markGlthen
in reply to: rikard.nilsson

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.

Message 14 of 20
rikard.nilsson
in reply to: markGlthen

Hi,

 

If you look at your row with oGeomIntent3. You use oCenterMark2. It should be oCenterMark3..

oGeomIntent3 = oSheet.CreateGeometryIntent(oCenterMark3, kPoint2dIntent)

 /Rikard

Message 15 of 20
markGlthen
in reply to: rikard.nilsson

@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?

 

Message 16 of 20
rikard.nilsson
in reply to: markGlthen

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

Message 17 of 20
Anonymous
in reply to: rikard.nilsson

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?

Message 18 of 20
HermJan.Otterman
in reply to: Anonymous

there is a method: "CenterText" that applies to LiniearGeneralDimension and AngularGeneralDimension.

so in you General dimensions, you have to filter these out (GeneralDimension.type)

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 19 of 20
Anonymous
in reply to: Anonymous

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") 

 

Message 20 of 20
rikard.nilsson
in reply to: Anonymous

Hi!
I think you need to understand the concept of Proxy..
If a point is in a sub assembly or part then you need to "move" that up to top level.. That is what proxy is about..
/Rikard

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report