Creating linear diameter dimension using API

Creating linear diameter dimension using API

Anonymous
Not applicable
1,633 Views
9 Replies
Message 1 of 10

Creating linear diameter dimension using API

Anonymous
Not applicable

Hi,

 

I have two sketch lines and its start point and end point and I need to add linear diameter dimension using API on those lines.

How do I create linear diameter dimension using API?

 

Please suggest me.

 

Regards,

Prarthana

0 Likes
Accepted solutions (1)
1,634 Views
9 Replies
Replies (9)
Message 2 of 10

Xun.Zhang
Alumni
Alumni

Hello, here is an example for how to create a diameter via API, hope it helps a little bit.

 

----------------------

Sub AddDiaDim()
Dim oPart As PartDocument
Set oPart = ThisApplication.Documents.Add(kPartDocumentObject)

Dim oCompDef As PartComponentDefinition
Set oCompDef = oPart.ComponentDefinition

Dim oPlnSk As PlanarSketch
Set oPlnSk = oCompDef.Sketches.Add(oCompDef.WorkPlanes("XY Plane"))

Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry

Dim oSkArc As SketchArc
Set oSkArc = oPlnSk.SketchArcs.AddByCenterStartEndPoint(oTG.CreatePoint2d(0, 0), oTG.CreatePoint2d(2, 4), oTG.CreatePoint2d(4, 4))

Dim oDiaDim As DiameterDimConstraint
Set oDiaDim = oPlnSk.DimensionConstraints.AddDiameter(oSkArc, oTG.CreatePoint2d(0, 0))

End Sub

---------------------------


Xun
Message 3 of 10

Anonymous
Not applicable
Thank you very much.
I will try this code and will let you know 🙂

Regards,
Prarthana
0 Likes
Message 4 of 10

Anonymous
Not applicable

Hi, 

 

I would like to explain my problem in detail.

 

I have selected these two lines from the code, Line 1 and Line 2  (marked in red).

And I have the Line1 start point and end point as (0, 3.5) and (3, 3.5)

and Line 2 which is a construction geometry line as (0,0) and (31, 0).

 

Now, what I need to do is to add the linear diameter dimension (ᴓ7) (marked in yellow color) using API of these two lines.

 

I hope I am able to explain my problem.Please help me.

 

Regards, 

Prarthanaキャプチャ.PNG

0 Likes
Message 5 of 10

Xun.Zhang
Alumni
Alumni

Hi,

 

I am a bit confused, do you want to add a linear diameter dimension between those two lines? is it correct? so which point is the start point and which one is the end? suppose start point should from one of line, right?

 

Could you help give me more details on the expectation result with a snapshot or sketch to show how the dimension lies finnally.

 

Thank you so much!


Xun
0 Likes
Message 6 of 10

Anonymous
Not applicable

Hi,

I am sorry for the confusion.

If I am not wrong, in order to create the linear diameter dimension we need to select the lines or with the points, right?

So for that, I select the two lines Line1 and Line2. The Line1  has its start point and end point and so with the Line2.

I do have the information of both the lines but what I need is to get the distance between these two lines (linear diameter) using API.

 

In the previous image, I created distance (marked in yellow)from the Inventor, but I need to create that dimension using API.キャプチャ1.PNG

0 Likes
Message 7 of 10

Xun.Zhang
Alumni
Alumni
Accepted solution

Hi, Clear enough now. 

 

please try below transcription.

 

----------------------------

Public Sub OffsetDimConstraint()
' Set a reference to the active sketch.
Dim oSketch As PlanarSketch
Set oSketch = ThisApplication.ActiveEditObject

' Set a reference to the transient geometry collection.
Dim oTransGeom As TransientGeometry
Set oTransGeom = ThisApplication.TransientGeometry

Dim oSketchLine As SketchLine
Set oSketchLine = oSketch.SketchLines.Item(1)

Dim oSketchEntity As SketchEntity
Set oSketchEntity = oSketch.SketchEntities.Item(6)

Dim oOffsetDimConstraint As OffsetDimConstraint
Set oOffsetDimConstraint = oSketch.DimensionConstraints.AddOffset(oSketchLine, oSketchEntity, oTransGeom.CreatePoint2d(0, 0), True)
End Sub

------------------------------------

 

0003.png


Xun
Message 8 of 10

Anonymous
Not applicable
Thank you very much.
It solved my problem . 🙂

Can I ask one more question?
Can we record the macro in Inventor like in Solidworks?

Regards,
Prarthana
0 Likes
Message 9 of 10

Xun.Zhang
Alumni
Alumni
Hi, Please copy all code in notepad and save as *.bas with type "all file", Open VBA Environment and File->import, then a new module is added.

Xun
Message 10 of 10

Anonymous
Not applicable
Hi,

Thank you very much for your help 🙂

With Regards,
Prarthana
0 Likes