LISP to display object info

LISP to display object info

Anonymous
Not applicable
1,392 Views
14 Replies
Message 1 of 15

LISP to display object info

Anonymous
Not applicable

What I'm trying to do is the following:

Pick one entity (line, arc, ellipse)

For a line, display the length and angle in XY plane (between 0-90deg) [10.5, 4.1°]

For an arc/ellipse, display the angle and radius (between 0-90deg) [12.1°, 5]

Put that output on the drawing with a leader pointing to the mid point of the entity

 

So far, I've gotten the picking the entity part, that's about it.  Any help with be greatly appreciated.  While I do have extensive programming skills in other languages, I'm just starting out with LISP.  Thanks in advance for any and all help!

0 Likes
1,393 Views
14 Replies
Replies (14)
Message 2 of 15

rkmcswain
Mentor
Mentor

Here is a little more help. I didn't get to adding the leader, it doesn't grab all the props you want, there is no error checking.......but it should get you going in the right direction.

 

 

(defun c:foo ( / sel ent obj objName LineLength MajorRadius Radius)
  (princ "\nSelect object: ")
  (setq sel (entsel))
  (setq ent (car sel))
  (setq obj (vlax-ename->vla-object ent))
  (setq objName (vla-get-ObjectName obj))
  (cond
    ((eq objName "AcDbLine")
     (setq LineLength (vla-get-Length obj))
    )
    ((eq objName "AcDbEllipse")
     (setq MajorRadius (vla-get-MajorRadius obj))
    )
    ((eq objName "AcDbArc")
     (setq Radius (vla-get-Radius obj))
    )
  )  
  (princ)
)
R.K. McSwain     | CADpanacea | on twitter
Message 3 of 15

Anonymous
Not applicable

Thanks!  Any suggestions on how i'd create the text on the screen (even if I just have to click a point to place it)?  I was looking at entmake?  Do you have other suggestions?

0 Likes
Message 4 of 15

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

 

....

For an arc/ellipse, display the angle and radius (between 0-90deg) [12.1°, 5]

....

Do you mean the included angle through which such an object sweeps?  That won't always be between 0 and 90 degrees [unless you would use this only in certain limited circumstances where it would], so might you mean the angle between its ends, or something else?

 

For an Ellipse, what is the "radius" -- the major half-axis [as rkmcswain assumes], or the minor one, or the average of those two, or the distance from the center to the midpoint where the Leader is supposed to point, or something else?

 

Would an Ellipse ever be closed?  If so, what would you want to be considered its midpoint to point to -- half-way around as AutoCAD stores data about it [one of the quadrant points]?

 

Something that might help steer you for part of it is ReportSlope.lsp, available here, which includes the conversion of any angle in any direction to be between 0 and 90 degrees relative to the X axis.

Kent Cooper, AIA
Message 5 of 15

rkmcswain
Mentor
Mentor

Well you could create a LEADER, MLEADER, TEXT, MTEXT, ----- it just depends on what you want to end up with.

LEADERS and MLEADERS are sort of tricky because those objects always have a style, from which their default properties are inherited. So just throwing one on the screen with code will get you something, but it may not look like you want. You'd probably want to check to see if the style you want exists, check the style props vs. what you expect them to be, etc. etc. If the style does not exist, then create it... etc.

Or you could brute force it, meaning create the object and then just set the properties to be what you want, overriding whatever defaults it inherited.



R.K. McSwain     | CADpanacea | on twitter
Message 6 of 15

Anonymous
Not applicable

IDK if this will help but, I'm working with profile drawings.  The objects i'm working with are lines and (part of) ellipsi; it's basically an arc segment but for whatever reason the civil draws it as an elipse.

 

I know the angle wouldn't always be between 0 and 90 but if it gives me like 92, I want it to print 2 and if it gives me 200, I want 20.

0 Likes
Message 7 of 15

rkmcswain
Mentor
Mentor

Kent1Cooper wrote:

For an Ellipse, what is the "radius" -- the major half-axis [as rkmcswain assumes]

Actually, I was simply illustrating how to get from selecting an object, to a point where you can query the objects available properties, such as MajorRadius, Length, etc.

 

However, I did make the presumption that OP would figure out that was an example only, and to tweak it as needed to fit the situation.

 

Smiley Happy

R.K. McSwain     | CADpanacea | on twitter
Message 8 of 15

Anonymous
Not applicable

Yeah I got that it was just an example and I'd need to find the proper properties for what I'm looking for.  All the radii are usually 5 for our application so I never actually measure them (unless they look off).  But I figured if I'm automating it all, why not just include it anyway.

0 Likes
Message 9 of 15

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... The objects i'm working with are lines and (part of) ellipsi; it's basically an arc segment but for whatever reason the civil draws it as an elipse.

....


They might be geometrically arcs.  If you define a Block including an Arc or a Circle, and Explode an inserted one with equal X and Y scales but a different Z scale, just as with different X & Y scales the arc or circle element will come out as an Ellipse, in this case it will also be an Ellipse, but with an axis ratio of 1, which is geometrically an arc [or circle if closed].  If there's something about the way the Civil drawings are done that is causing that kind of thing with what could really be Arc entities, you could convert them.  They'd take slightly less memory, and probably be easier to work with.  You can look at their axis ratios.  If an Ellipse's Entity Data contains (40 . 1.0) or its RadiusRatio VLA Property is 1.0, it could be converted.  I have some routines with code that will help do that, if you want.

Kent Cooper, AIA
Message 10 of 15

Anonymous
Not applicable

Yeah listed the ellipse, Radius Ratio: 1.00000

 

If you have a lisp to convert ellipse to arc that'd be great.  Right now I use dimang and dimalign to get the dimensions and just throw them all over the place.  The ellipse take longer because dimang can't work with ellipse so I have to pick the points.  It'd be a big help in the mean time while I work on this automation lisp.

0 Likes
Message 11 of 15

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....

I know the angle wouldn't always be between 0 and 90 but if it gives me like 92, I want it to print 2 and if it gives me 200, I want 20.


ArcAngle.png

A sample drawing or image would be helpful.

Kent Cooper, AIA
Message 12 of 15

Anonymous
Not applicable

I went and looked at the ellipse angles and they're all under 90 so I don't think that's a concern (more error checking I suppose but I could just manually QA that as it rarely happens.

 

The angle that's not always between 0 and 90 is that of the lines.  Some of the lines show: Angle in XY Plane =   4.00, while others show Angle in XY Plane = 183.87.  The first one, I can just have it as 4deg.  The 2nd I'd like it to display at 3.87deg.

 

The attached screen shoot is a section of what I do now (the dim lines in red) vs what I start with (the blank portion to the right).

0 Likes
Message 13 of 15

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Yeah listed the ellipse, Radius Ratio: 1.00000

 

If you have a lisp to convert ellipse to arc that'd be great.  ....


There's a routine to Reverse Entity Direction, and another one to close Arcs or arc-equivalent partial Ellipses or one-segment Polylines into Circles, both of which know how to detect an Ellipse with equal axes, and work with it differently because it's geometrically an arc, if you want to start taking a look.  In the case of ReverseDirection.lsp, using that on an arc-equivalent Ellipse and then Exploding the resulting Polyline would give you an Arc, so that's already probably closer to what you need.  In the case of ArcClose.lsp, it turns things into full Circles, but at least you can look at how it figures it out.  I can't play with that further until tomorrow.

Kent Cooper, AIA
Message 14 of 15

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... Some of the lines show: Angle in XY Plane =   4.00, while others show Angle in XY Plane = 183.87.  The first one, I can just have it as 4deg.  The 2nd I'd like it to display at 3.87deg.

 

The attached screen shoot is a section of what I do now (the dim lines in red) vs what I start with (the blank portion to the right).


For the Lines, that's exactly what ReportSlope.lsp figures out, so that's a start.

 

For the Arcs, that image makes it clear that it's the included or sweep angle you're after.

Kent Cooper, AIA
Message 15 of 15

Anonymous
Not applicable

Thanks Kent, you've been a huge help.  I've got a heap of learning to do real quick.

0 Likes