Using Osnap in LISP

Using Osnap in LISP

Muhammed.OPERA
Advisor Advisor
3,654 Views
11 Replies
Message 1 of 12

Using Osnap in LISP

Muhammed.OPERA
Advisor
Advisor

Hi everyone 🙂

Can i use object snap to grip the endpoint of certain line.

I know that osnap function is using a point on the line i need to snap on one of it's points.

but the line is made with offset command and i don't know any point near it.

 

There is another question:

Can i use fillet command with two lines saved in variables Line1 , Line2

I tried too many times but it says nil.

that's the code i used:

(Setvar "FILLETRAD" 0)
(command "Fillet" "Trim" "Trim" Line1 Line2)

Thanks 🙂


Muhammed Mamdouh (OPERA)
Structural Engineer, Instructor
Facebook |LinkedIn

EESignature

0 Likes
3,655 Views
11 Replies
Replies (11)
Message 2 of 12

Muhammed.OPERA
Advisor
Advisor

Hi everyone 🙂

Can i use object snap to grip the endpoint of certain line.

I know that osnap function is using a point on the line i need to snap on one of it's points.

but the line is made with offset command and i don't know any point near it.

 

There is another question:

Can i use fillet command with two lines saved in variables Line1 , Line2

I tried too many times but it says nil.

that's the code i used:

(Setvar "FILLETRAD" 0)
(command "Fillet" "Trim" "Trim" Line1 Line2)

Thanks 🙂


Muhammed Mamdouh (OPERA)
Structural Engineer, Instructor
Facebook |LinkedIn

EESignature

0 Likes
Message 3 of 12

paullimapa
Mentor
Mentor

Object snap:

You can use the same object snap functions to snap to a Line that is offset from another Line.  There is really no difference between the two.  Lines always have two end points and one mid point that you can object snap to.

 

Fillet:

You should be able to use the following code to Fillet two selected Lines:

(setq ln1(car(entsel"\nPick First Line:")))

(setq ln2(car(entsel"\nPick Second Line:")))

(if (and ln1 ln2)(command"_.Fillet" ln1 ln2))

 

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales | Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 12

Ranjit_Singh
Advisor
Advisor

@Muhammed.OPERA wrote:

Hi everyone 🙂

Can i use object snap to grip the endpoint of certain line.

I know that osnap function is using a point on the line i need to snap on one of it's points.

but the line is made with offset command and i don't know any point near it.

Retrieve the last entity using (entlast) and then process the entity data as needed to get the endpoint

 

There is another question:

Can i use fillet command with two lines saved in variables Line1 , Line2

I tried too many times but it says nil.

that's the code i used:

(Setvar "FILLETRAD" 0)
(command "Fillet" "Trim" "Trim" Line1 Line2)

Thanks 🙂

Trim function needs a point and entity, (if not being selected on screen) not just entity name. Also follow the command prompts to see where the cutting edges selction ends and where the trim object selection begins


 

Message 5 of 12

Kent1Cooper
Consultant
Consultant

You can get endpoints if you have the entity name of the new Line, with a couple of approaches.  But post an image -- the ways I'm thinking of would require knowing which is the startpoint and which the endpoint, but there may be a way to compensate if that's not known.

 

FILLET requires not just an object or entity name, but a point  as well [as if you were picking it manually], so that it can figure out which end of the [in your case] Line to adjust.  Again, an image or sample drawing of the situation may reveal a way to accomplish that.

Kent Cooper, AIA
Message 6 of 12

ВeekeeCZ
Consultant
Consultant

It you don't have point from the selection, you can use any on the line... 

 

(command "fillet"
         (list line1 (cdr (assoc 10 (entget line1))))
         (list line2 (cdr (assoc 10 (entget line2)))))
0 Likes
Message 7 of 12

Muhammed.OPERA
Advisor
Advisor

I have sent you @Kent1Cooper @Ranjit_Singh

the full code i used.

Thanks you very much 🙂


Muhammed Mamdouh (OPERA)
Structural Engineer, Instructor
Facebook |LinkedIn

EESignature

0 Likes
Message 8 of 12

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:

It you don't have point from the selection, you can use any on the line... 


... if you're careful, and the circumstances are right.  With some situations, such as a T-like relationship, you'll get different results from different points.

Kent Cooper, AIA
0 Likes
Message 9 of 12

Muhammed.OPERA
Advisor
Advisor

Sorry this is a duplicated post that i'm gonna delete.

This is the post:

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/using-osnap-in-lisp/td-p/7618130

I hope you can help 🙂

Thanks


Muhammed Mamdouh (OPERA)
Structural Engineer, Instructor
Facebook |LinkedIn

EESignature

0 Likes
Message 10 of 12

john.uhden
Mentor
Mentor

You really can't make grips hot (red) with AutoLisp, but at least you can make them blue.

If the offset object is the last thing created, then you can:

 

(sssetfirst nil (ssadd entlast))

If you are talking about the osnap function, be careful.  You may end up getting a point on an object other than intended. I find using Visual Lisp much more reliable.  For example, if you want the nearest point on a curve object (line, arc, polyline, spline, etc.) from a point P.1 then:

 

(setq P2 (vlax-curve-getclosestpointto object P1))
and then if you want to find the nearest endpoint to P2...
(setq P2 (osnap P2 "_end"))

which is more likely to return a point on the desired object.

Also study the help for the difference between vlax-curve-getclosestpointo and vlax-curve-getclosestpointtoprojecttion.  More often I find that the projection is what I need, especially with 3D polylines.

John F. Uhden

0 Likes
Message 11 of 12

paullimapa
Mentor
Mentor

Object snap:

As others have posted, you can retrieve the last object in this case the Line you've just Offset using:

(setq obl (entlast)) 

 

Next you can retrieve the two endpoints of this new Line using:

(setq obd (entget obl)) ; get Line's properties

(setq pt1 (cdr(assoc 10 obd))) ; get Line's endpoint #1

(setq pt2 (cdr(assoc 11 obd))) ; get Line's endpoint #2

 

Now that you have the new Line's endpoints, you can draw a new Object like a Circle from these two points:

 

(command"_.Circle" "_2p" pt1 pt2)

 

There's no need to use Object snap options to snap to the endpoints.

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales | Exchange App Store

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 12 of 12

john.uhden
Mentor
Mentor

Oops.

That was supposed to be:

 

(sssetfirst nil (ssadd (entlast)))

I missed a couple of parentheses.

John F. Uhden

0 Likes