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: 

Adding dimensions to a sketch

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
217 Views, 2 Replies

Adding dimensions to a sketch

Hi all,

I am having trouble adding dimensions in my sketch! Can anyone give me a
pointer?
The code I have so far:

*****
Private Sub GenerateVessel()

' Import the parameters from the Userform
Dim TT, VID As Double
VID = UserForm1.TextBox1.Value / 10
TT = UserForm1.TextBox2.Value / 10
THK = UserForm1.TextBox3.Value / 10

' Create a new part document, using the default part template.
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject,
ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))

' Set a reference to the component definition.
Dim oPartCompDef As PartComponentDefinition
Set oPartCompDef = ThisApplication.ActiveDocument.ComponentDefinition

' Create a new sketch.
Dim oSketch As Sketch
Set oSketch = oPartCompDef.Sketches.Add(oPartCompDef.WorkPlanes.Item(3))

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

' Create the sketch points for the vessel shell
Dim oCoord(1 To 6) As Point2d
Set oCoord1 = oTransGeom.CreatePoint2d(0, 0)
Set oCoord2 = oTransGeom.CreatePoint2d(TT, 0)
Set oCoord3 = oTransGeom.CreatePoint2d(0, (VID / 2))
Set oCoord4 = oTransGeom.CreatePoint2d(TT, (VID / 2))
Set oCoord5 = oTransGeom.CreatePoint2d(0, (VID / 2) + THK)
Set oCoord6 = oTransGeom.CreatePoint2d(TT, (VID / 2) + THK)

' Create line between 2 point
Dim oLine(1 To 5) As SketchLine
Set oLine(1) = oSketch.SketchLines.AddByTwoPoints(oCoord3, oCoord4)
Set oLine(2) = oSketch.SketchLines.AddByTwoPoints(oLine(1).EndSketchPoint,
oCoord6)
Set oLine(3) = oSketch.SketchLines.AddByTwoPoints(oLine(2).EndSketchPoint,
oCoord5)
Set oLine(4) = oSketch.SketchLines.AddByTwoPoints(oLine(3).EndSketchPoint,
oLine(1).StartSketchPoint)
Set oLine(5) = oSketch.SketchLines.AddByTwoPoints(oCoord1, oCoord2)

' Add 2D Constrains to lines (not complete yet)
Call oSketch.GeometricConstraints.AddGround(oLine(1).StartSketchPoint)
Call oSketch.GeometricConstraints.AddHorizontal(oLine(1))
Call oSketch.GeometricConstraints.AddPerpendicular(oLine(1), oLine(2))
Call oSketch.GeometricConstraints.AddParallel(oLine(3), oLine(1))
Call oSketch.GeometricConstraints.AddVertical(oLine(4))
Call oSketch.GeometricConstraints.AddHorizontal(oLine(5))

' Add dimensions to lines (what am I doing wrong here? Or, what have I done
right?)
Dim AddTwoPointDistance As DimensionConstraints
Call
oSketch.DimensionConstraints.AddTwoPointDistance(oLine(1).StartSketchPoint,
oLine(1).EndSketchPoint, kHorizontalDim, oLine(5).StartSketchPoint, True)

' Create a profile.
Dim oProfile As Profile
Set oProfile = oSketch.Profiles.AddForSolid

' Create a base revolve, 360 degrees.
Call oPartCompDef.Features.RevolveFeatures.AddFull(oProfile, oLine(5),
kJoinOperation)

End Sub
*****
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

I think you need a Point2d instead of a sketch point for the dimension text placement
point.(your oLine(5).startSketchPoint in the code)

--
Kent
Assistant Moderator
Autodesk Discussion Forum Moderator Program


"Teun Ham" wrote in message
news:A51868868A5262D4FC587062C418B844@in.WebX.maYIadrTaRb...
> ' Add dimensions to lines (what am I doing wrong here? Or, what have I done
> right?)
> Dim AddTwoPointDistance As DimensionConstraints
> Call
> oSketch.DimensionConstraints.AddTwoPointDistance(oLine(1).StartSketchPoint,
> oLine(1).EndSketchPoint, kHorizontalDim, oLine(5).StartSketchPoint, True)
Message 3 of 3
Anonymous
in reply to: Anonymous

Thanks Kent!

Adding another oCoord (Point2d) and referring the dim to that point was the
trick.

T.

"Kent Keller" wrote in message
news:6F246734F1AB8506008A77ECA5630EBD@in.WebX.maYIadrTaRb...
> I think you need a Point2d instead of a sketch point for the dimension
text placement
> point.(your oLine(5).startSketchPoint in the code)
>
> --
> Kent
> Assistant Moderator
> Autodesk Discussion Forum Moderator Program
>
>
> "Teun Ham" wrote in message
> news:A51868868A5262D4FC587062C418B844@in.WebX.maYIadrTaRb...
> > ' Add dimensions to lines (what am I doing wrong here? Or, what have I
done
> > right?)
> > Dim AddTwoPointDistance As DimensionConstraints
> > Call
> >
oSketch.DimensionConstraints.AddTwoPointDistance(oLine(1).StartSketchPoint,
> > oLine(1).EndSketchPoint, kHorizontalDim, oLine(5).StartSketchPoint,
True)
>
>

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

Post to forums  

Autodesk Design & Make Report