Arc/curve center point and dimension placement

Arc/curve center point and dimension placement

Anonymous
Not applicable
298 Views
4 Replies
Message 1 of 5

Arc/curve center point and dimension placement

Anonymous
Not applicable
Hi,

Does anyone know how I can apply sketch constraints to an arc in a sketch in
MCAD VBA? More specifically, I'm trying to find the centre point of the
arc. I've tried to do this simply in Acad 2000, to select an arc and place
a dimension showing the radius but haven't had any luck.

Thanks

Guy

--
--
Guy Bursell
CAD Development Engineer
Mabey & Johnson Ltd.
0 Likes
299 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Guy Bursell

How about using properties, that is
Startpoint, Endpoint, and Center
--
________Junichi Yoda______________________________________
Page of AutoCAD VBA
http://plaza13.mbn.or.jp/~yoda/AutoCADVBA
Download Visio shapes for piping isometrics
http://www.geocities.com/piping_isometrics/

Guy Bursell wrote in message
news:81iu0s$ctc8@adesknews2.autodesk.com...
> Hi,
>
> Does anyone know how I can apply sketch constraints to an arc in a sketch
in
> MCAD VBA? More specifically, I'm trying to find the centre point of the
> arc. I've tried to do this simply in Acad 2000, to select an arc and
place
> a dimension showing the radius but haven't had any luck.
>
> Thanks
>
> Guy
>
> --
> --
> Guy Bursell
> CAD Development Engineer
> Mabey & Johnson Ltd.
>
>
>
0 Likes
Message 3 of 5

Anonymous
Not applicable
Guy,

Create sketch constraints with a constraint descriptor and the AddConstraint
method on McadSketch. As with the AMPROFILE command, when an arc is used as
an operand in a distance constraint, the center is inferred, so you should
only need to use the arc as one of the operands of the desired constraint
type.

The only trick to creating sketch constraints is that the operands are
expected to be 'focused' to the sketch. Sketch geometry lives a kind of
dual life, the geometry that you see (instanced in model space and
transformed to the active instance), and the internal geometry in the part
definition (the stuff that lives on when the sketch is consumed). When you
pick and highlight sketch geometry, you deal in the display geometry. When
you ask a sketch for it's geometry or create or query a constraint, you deal
with the internal sketch geometry. You can use McadUtility.RefocusObject
with the McadSketch as the reference object to convert from the display
geometry to the sketch geometry. At this time there is no usable refocus
reference object, and therefore easy way, to go from sketch geometry to
display (the display geometry comes and goes, and moves in and out of the
part's component definition depending on the active state of the part, so it
isn't as useful as you would think).

The example below creates a simple horizontal sketch constraint, with the
first operand being an arc. The constraint creation automatically infers
the center point of the arc, but if you want you could use
McadUtility.InferGeometry or the infer options on GetGeometryFromPick to
manually infer the center point yourself before creation (or for any other
reason).

Kris

Sub test()
Dim mcad As McadApplication
Set mcad =
ThisDrawing.Application.GetInterfaceObject("Mcad.Application")
Dim ge As GeApplication
Set ge = ThisDrawing.Application.GetInterfaceObject("Ge.Application")
Dim util As McadUtility
Set util = mcad.ActiveDocument.Utility

' pick an arc
Dim pick As McadPick
Set pick = util.pick("Select sketch arc", mcArc)
Dim arc As McadArc
Set arc = util.GetObjectFromPick(pick)

' reuse the pick to locate the sketch
' (will fail if didn't select sketch arc)
Dim sketch As McadSketch
pick.ObjectType = mcSketch
Set sketch = util.GetObjectFromPick(pick)

' refocus to get the arc in the sketch (not the display)
util.RefocusObject arc, sketch

' select another point on the sketch (should ckeck for 'same' sketch)
Set pick = util.pick("H distance from center to", mcPoint)
Dim point As McadPoint
Set point = util.GetGeometryFromPick(mcPoint, True, pick)
util.RefocusObject point, sketch

' get the dimension display location
Dim gePt As GePoint
Set gePt = ge.point
gePt.AsArray = ThisDrawing.Utility.GetPoint(, "dimension location: ")

' create the constraint
Dim desc As McadConstraintDescriptor
Set desc = util.CreateConstraintDescriptor(mcSkHorizontalDistance)
desc.Displayed = True
desc.Operand1 = arc
desc.Operand2 = point
desc.DisplayLocation = gePt
Dim length As McadValue
Set length = util.CreateValue
length = ThisDrawing.Utility.GetDistance(, "Length: ")
desc.Value = length
sketch.AddConstraint desc
End Sub

Guy Bursell wrote in message <81iu0s$ctc8@adesknews2.autodesk.com>...
>Hi,
>
>Does anyone know how I can apply sketch constraints to an arc in a sketch
in
>MCAD VBA? More specifically, I'm trying to find the centre point of the
>arc. I've tried to do this simply in Acad 2000, to select an arc and place
>a dimension showing the radius but haven't had any luck.
>
>Thanks
>
>Guy
>
0 Likes
Message 4 of 5

Anonymous
Not applicable
Hi Kris,

Thanks for the info. From the sample you posted below I can apply the types
of constraints that I want. Is it possible to apply the same constraints as
below but without user selected - using points? I can easily calculate the
points I need to select the geometry at but I can't figure out how to apply
these into the constraints. Any ideas??

Many thanks

Guy.

--
Guy Bursell
CAD Development Engineer
Mabey & Johnson Ltd.

Kris Kaplan wrote in message
news:81uagd$3bd12@adesknews2.autodesk.com...
>
> Guy,
>
> Create sketch constraints with a constraint descriptor and the
AddConstraint
> method on McadSketch. As with the AMPROFILE command, when an arc is used
as
> an operand in a distance constraint, the center is inferred, so you should
> only need to use the arc as one of the operands of the desired constraint
> type.
>
> The only trick to creating sketch constraints is that the operands are
> expected to be 'focused' to the sketch. Sketch geometry lives a kind of
> dual life, the geometry that you see (instanced in model space and
> transformed to the active instance), and the internal geometry in the part
> definition (the stuff that lives on when the sketch is consumed). When
you
> pick and highlight sketch geometry, you deal in the display geometry.
When
> you ask a sketch for it's geometry or create or query a constraint, you
deal
> with the internal sketch geometry. You can use McadUtility.RefocusObject
> with the McadSketch as the reference object to convert from the display
> geometry to the sketch geometry. At this time there is no usable refocus
> reference object, and therefore easy way, to go from sketch geometry to
> display (the display geometry comes and goes, and moves in and out of the
> part's component definition depending on the active state of the part, so
it
> isn't as useful as you would think).
>
> The example below creates a simple horizontal sketch constraint, with the
> first operand being an arc. The constraint creation automatically infers
> the center point of the arc, but if you want you could use
> McadUtility.InferGeometry or the infer options on GetGeometryFromPick to
> manually infer the center point yourself before creation (or for any other
> reason).
>
> Kris
>
>
> Sub test()
> Dim mcad As McadApplication
> Set mcad =
> ThisDrawing.Application.GetInterfaceObject("Mcad.Application")
> Dim ge As GeApplication
> Set ge = ThisDrawing.Application.GetInterfaceObject("Ge.Application")
> Dim util As McadUtility
> Set util = mcad.ActiveDocument.Utility
>
> ' pick an arc
> Dim pick As McadPick
> Set pick = util.pick("Select sketch arc", mcArc)
> Dim arc As McadArc
> Set arc = util.GetObjectFromPick(pick)
>
> ' reuse the pick to locate the sketch
> ' (will fail if didn't select sketch arc)
> Dim sketch As McadSketch
> pick.ObjectType = mcSketch
> Set sketch = util.GetObjectFromPick(pick)
>
> ' refocus to get the arc in the sketch (not the display)
> util.RefocusObject arc, sketch
>
> ' select another point on the sketch (should ckeck for 'same' sketch)
> Set pick = util.pick("H distance from center to", mcPoint)
> Dim point As McadPoint
> Set point = util.GetGeometryFromPick(mcPoint, True, pick)
> util.RefocusObject point, sketch
>
> ' get the dimension display location
> Dim gePt As GePoint
> Set gePt = ge.point
> gePt.AsArray = ThisDrawing.Utility.GetPoint(, "dimension location: ")
>
> ' create the constraint
> Dim desc As McadConstraintDescriptor
> Set desc = util.CreateConstraintDescriptor(mcSkHorizontalDistance)
> desc.Displayed = True
> desc.Operand1 = arc
> desc.Operand2 = point
> desc.DisplayLocation = gePt
> Dim length As McadValue
> Set length = util.CreateValue
> length = ThisDrawing.Utility.GetDistance(, "Length: ")
> desc.Value = length
> sketch.AddConstraint desc
> End Sub
>
> Guy Bursell wrote in message <81iu0s$ctc8@adesknews2.autodesk.com>...
> >Hi,
> >
> >Does anyone know how I can apply sketch constraints to an arc in a sketch
> in
> >MCAD VBA? More specifically, I'm trying to find the centre point of the
> >arc. I've tried to do this simply in Acad 2000, to select an arc and
place
> >a dimension showing the radius but haven't had any luck.
> >
> >Thanks
> >
> >Guy
> >
>
>
>
0 Likes
Message 5 of 5

Anonymous
Not applicable
Guy,

It depends on what you mean by 'points'. If you mean the coordinates of an
endpoint or something, you can use these coordinates to programatically
select the objects, but I would avoid this approach. I would construct the
sketch geometry with the AutoCAD API (not sendkeys), use the objectIDs of
these entities to fill a sketch descriptor and construct the sketch, take
the resulting McadSketch object and query for it's geometry, infer any
McadPoint endpoints you may need from the sketch geometry to use in a
constraint descriptor.

Kris

Guy Bursell wrote in message <820vre$9n26@adesknews2.autodesk.com>...
>Hi Kris,
>
>Thanks for the info. From the sample you posted below I can apply the
types
>of constraints that I want. Is it possible to apply the same constraints
as
>below but without user selected - using points? I can easily calculate the
>points I need to select the geometry at but I can't figure out how to apply
>these into the constraints. Any ideas??
>
>Many thanks
>
>Guy.
>
>--
>Guy Bursell
>CAD Development Engineer
>Mabey & Johnson Ltd.
0 Likes