Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
*Rick Keller
Message 1 of 12 (211 Views)

Continuous Offset with last entity & diff dist...

211 Views, 11 Replies
06-23-2005 09:49 AM
I am trying to write a lisp routine that will offset a line then
automatically select the new line and ask for a new distance.

It is not working like I thought it would... Any Help / suggestions?

Here is what I have:

(defun c:mul (/)
(setq myent (entsel))
(command "offset" pause myent pause "")
(setq newent (entget (entlast)))
(while (/= newent nil)
(command "offset" pause newent pause "")
(setq newent (entget (entlast)))
)
)


Thanks
Rick
Mentor
t.willey
Posts: 2,504
Registered: ‎02-17-2004
Message 2 of 12 (211 Views)

Re: Continuous Offset with last entity & diff dist...

06-23-2005 10:12 AM in reply to: *Rick Keller
(defun c:mul (/ myent)
(setq myent (entsel))
(command "offset" pause myent pause "")
(setq newent (entlast))
(while (/= newent nil)
(command "offset" pause newent pause "")
(setq newent (entlast))
)
)


Took out the entget before the entlast, not needed (two places). The way it works now you will have to cancel it with and escape key.

Tim
*Rick Keller
Message 3 of 12 (211 Views)

Re: Continuous Offset with last entity & diff dist...

06-23-2005 10:43 AM in reply to: *Rick Keller
Thanks..

I knew it couldnt be that hard, Its nice to know I was closer than I
thought.

Rick


wrote in message news:4883463@discussion.autodesk.com...
(defun c:mul (/ myent)
(setq myent (entsel))
(command "offset" pause myent pause "")
(setq newent (entlast))
(while (/= newent nil)
(command "offset" pause newent pause "")
(setq newent (entlast))
)
)


Took out the entget before the entlast, not needed (two places). The way it
works now you will have to cancel it with and escape key.

Tim
Mentor
t.willey
Posts: 2,504
Registered: ‎02-17-2004
Message 4 of 12 (211 Views)

Re: Continuous Offset with last entity & diff dist...

06-23-2005 11:01 AM in reply to: *Rick Keller
You're welcome. Happy to help when I can.

Tim
*Alex
Message 5 of 12 (211 Views)

Re: Continuous Offset with last entity & diff dist...

06-24-2005 05:41 AM in reply to: *Rick Keller
This may also help. Hopefully I included all the sub routines.

; mvo multi variable offset BY ALEX KONIECZKA
(defun c:mvo ()
(print "Select object to offset: ")(gent)
(setq tpt entpt tpt1 (getpoint "Select side to offset: ") dd 0 tang (angle
entpt tpt1))


(while (setq d (getstring "Enter an offset value (*# for multiple) :"))

(if (= "*" (substr d 1 1))
(progn (setq n (atoi (substr d 2)) d (getstring "Distance: : ") d (atof
) ))
(progn (setq n 1 d (atof d) ))
) ;if

(repeat n (progn

(SETQ DD (+ DD D) tpt (polar tpt tang dd) )
(command "offset" d entn tpt "")(gents (entlast))
))

); while
(princ) )


; offset from base pick a base point and hold the cursor on the side you
want to offset and start typing #'s

(defun c:smileysurprised:b ()
(print "Select base object to offset from and put currsor on the offset
side, then type numbers: ")(gent)
(while (setq d (getstring "Enter an offset value (*# for multiple) :"))
(setq tpt1 (cadr (grread 1)))
(setq tpt entpt dd 0 tang (angle entpt tpt1))
(command "offset" d entn tpt1 "")
); while
(princ) )

; ot offset through will change layer to the picked item.
(defun c:smileysurprised:t ()
(print "Select base object to offset: ")(gent)(setq e (car entn))
(while (gent)
(setq layn (ass 8) tpt1 entpt)
(command "offset" "t" e tpt1 "")
(gents (entlast))(modent 8 layn)
); while
(princ) )



; dof = double offset to current layer

(defun c:dof ()
(setq d (getval d "Enter doffset: "))
(while (print "Select line to offset: ")(gent)
(if (= (ass 0) "LINE")(progn
(setq e entn tpt1 (polar (ass 10) (+ (angle (ass 10) (ass 11)) (/ pi 2))
1) tpt2 (polar (ass 10) (+ (angle (ass 10) (ass 11)) (/ pi -2)) 1) )
(command "offset" d e tpt1 "")(gents (entlast))(modent 8 (getvar
"clayer"))
(command "offset" d e tpt2 "")(gents (entlast))(modent 8 (getvar
"clayer"))
)))
(princ))

; gent returns the entity name of the item picked
(defun gent ()
(setq entn (entsel))
(setq entcodes (entget (car entn)))
(setq entpt (cadr entn))
(setq entt (cdr (assoc 0 entcodes)))
)

; ass returns the (cdr (assoc n)) of the the item. (ass 10) => (10 . 1 2 3)
(defun ass (code / )
(cdr (assoc code entcodes))
)

; gents returns the entity name of the item passed to it from a selction set
(defun gents (entname /)
(setq entn entname entcodes (entget entn) entpt nil)
(setq entt (cdr (assoc 0 entcodes)))
(princ))




"Rick Keller" wrote in message
news:4883417@discussion.autodesk.com...
I am trying to write a lisp routine that will offset a line then
automatically select the new line and ask for a new distance.

It is not working like I thought it would... Any Help / suggestions?

Here is what I have:

(defun c:mul (/)
(setq myent (entsel))
(command "offset" pause myent pause "")
(setq newent (entget (entlast)))
(while (/= newent nil)
(command "offset" pause newent pause "")
(setq newent (entget (entlast)))
)
)


Thanks
Rick
*Kent Cooper
Message 6 of 12 (211 Views)

Re: Continuous Offset with last entity & diff dist...

06-24-2005 06:07 AM in reply to: *Rick Keller
[Not in response to the latest message from Alex, but to the original post,
which I didn't keep to reply to directly....]

If you're really talking about Lines (and Xlines and Rays) ONLY, here's
another approach that would work:

Ask the user to select the Line, and from its association list, rotate
SNAPANG to align with its endpoints (assoc 10 & 11). Turn ortho on and ask
to which side to "offset" it, and save that angle. (Then you can set
SNAPANG back where it was, and turn ortho off.) Then ask for the first
"offset" distance, and Copy that selected Line at the saved angle and the
given distance. Ask for the next distance, and do a "while" loop: as long
as the user keeps giving a new distance, Copy the Last item, again at the
saved angle and the latest given distance. (That's why I put "offset" in
quotes earlier -- it's not really doing it by offsetting.)

This AVOIDS the "problem" that Offset wants object selection to be by a
point (you can't use Last with Offset, as you can with Copy).

It wouldn't work as Offset does with Circles, Arcs, most Polylines, etc.,
but would be exactly equivalent with Lines, Xlines, Rays, and
single-line-segment Polylines.
--
Kent Cooper


"Rick Keller" wrote...
I am trying to write a lisp routine that will offset a line then
automatically select the new line and ask for a new distance.

It is not working like I thought it would... Any Help / suggestions?

Here is what I have:

(defun c:mul (/)
(setq myent (entsel))
(command "offset" pause myent pause "")
(setq newent (entget (entlast)))
(while (/= newent nil)
(command "offset" pause newent pause "")
(setq newent (entget (entlast)))
)
)


Thanks
Rick
*Rick Keller
Message 7 of 12 (211 Views)

Re: Continuous Offset with last entity & diff dist...

06-24-2005 06:52 AM in reply to: *Rick Keller
Yes Alex that is exactly what I was driving for (mvo).

Thanks for the code. What I had was working but I was going to refine it to
work
just like yours does.

Thanks again.
Rick


"Alex" wrote in message
news:4884360@discussion.autodesk.com...
This may also help. Hopefully I included all the sub routines.

; mvo multi variable offset BY ALEX KONIECZKA
(defun c:mvo ()
(print "Select object to offset: ")(gent)
(setq tpt entpt tpt1 (getpoint "Select side to offset: ") dd 0 tang (angle
entpt tpt1))


(while (setq d (getstring "Enter an offset value (*# for multiple) :"))

(if (= "*" (substr d 1 1))
(progn (setq n (atoi (substr d 2)) d (getstring "Distance: : ") d (atof
) ))
(progn (setq n 1 d (atof d) ))
) ;if

(repeat n (progn

(SETQ DD (+ DD D) tpt (polar tpt tang dd) )
(command "offset" d entn tpt "")(gents (entlast))
))

); while
(princ) )


; offset from base pick a base point and hold the cursor on the side you
want to offset and start typing #'s

(defun c:smileysurprised:b ()
(print "Select base object to offset from and put currsor on the offset
side, then type numbers: ")(gent)
(while (setq d (getstring "Enter an offset value (*# for multiple) :"))
(setq tpt1 (cadr (grread 1)))
(setq tpt entpt dd 0 tang (angle entpt tpt1))
(command "offset" d entn tpt1 "")
); while
(princ) )

; ot offset through will change layer to the picked item.
(defun c:smileysurprised:t ()
(print "Select base object to offset: ")(gent)(setq e (car entn))
(while (gent)
(setq layn (ass 8) tpt1 entpt)
(command "offset" "t" e tpt1 "")
(gents (entlast))(modent 8 layn)
); while
(princ) )



; dof = double offset to current layer

(defun c:dof ()
(setq d (getval d "Enter doffset: "))
(while (print "Select line to offset: ")(gent)
(if (= (ass 0) "LINE")(progn
(setq e entn tpt1 (polar (ass 10) (+ (angle (ass 10) (ass 11)) (/ pi 2))
1) tpt2 (polar (ass 10) (+ (angle (ass 10) (ass 11)) (/ pi -2)) 1) )
(command "offset" d e tpt1 "")(gents (entlast))(modent 8 (getvar
"clayer"))
(command "offset" d e tpt2 "")(gents (entlast))(modent 8 (getvar
"clayer"))
)))
(princ))

; gent returns the entity name of the item picked
(defun gent ()
(setq entn (entsel))
(setq entcodes (entget (car entn)))
(setq entpt (cadr entn))
(setq entt (cdr (assoc 0 entcodes)))
)

; ass returns the (cdr (assoc n)) of the the item. (ass 10) => (10 . 1 2 3)
(defun ass (code / )
(cdr (assoc code entcodes))
)

; gents returns the entity name of the item passed to it from a selction set
(defun gents (entname /)
(setq entn entname entcodes (entget entn) entpt nil)
(setq entt (cdr (assoc 0 entcodes)))
(princ))




"Rick Keller" wrote in message
news:4883417@discussion.autodesk.com...
I am trying to write a lisp routine that will offset a line then
automatically select the new line and ask for a new distance.

It is not working like I thought it would... Any Help / suggestions?

Here is what I have:

(defun c:mul (/)
(setq myent (entsel))
(command "offset" pause myent pause "")
(setq newent (entget (entlast)))
(while (/= newent nil)
(command "offset" pause newent pause "")
(setq newent (entget (entlast)))
)
)


Thanks
Rick
*Rick Keller
Message 8 of 12 (211 Views)

Re: Continuous Offset with last entity & diff dist...

06-24-2005 07:00 AM in reply to: *Rick Keller
Thanks,

That is another way of solving the problem.

I am usually only copying/offsetting lines mostly gridlines for buildings.

The truth is I only need something simple but thanks for the different view
on the problem.

I was wondering how I could mimic offsetting to a side like AutoCAD does.

Rick



"Kent Cooper" wrote in message
news:4884420@discussion.autodesk.com...
[Not in response to the latest message from Alex, but to the original post,
which I didn't keep to reply to directly....]

If you're really talking about Lines (and Xlines and Rays) ONLY, here's
another approach that would work:

Ask the user to select the Line, and from its association list, rotate
SNAPANG to align with its endpoints (assoc 10 & 11). Turn ortho on and ask
to which side to "offset" it, and save that angle. (Then you can set
SNAPANG back where it was, and turn ortho off.) Then ask for the first
"offset" distance, and Copy that selected Line at the saved angle and the
given distance. Ask for the next distance, and do a "while" loop: as long
as the user keeps giving a new distance, Copy the Last item, again at the
saved angle and the latest given distance. (That's why I put "offset" in
quotes earlier -- it's not really doing it by offsetting.)

This AVOIDS the "problem" that Offset wants object selection to be by a
point (you can't use Last with Offset, as you can with Copy).

It wouldn't work as Offset does with Circles, Arcs, most Polylines, etc.,
but would be exactly equivalent with Lines, Xlines, Rays, and
single-line-segment Polylines.
--
Kent Cooper


"Rick Keller" wrote...
I am trying to write a lisp routine that will offset a line then
automatically select the new line and ask for a new distance.

It is not working like I thought it would... Any Help / suggestions?

Here is what I have:

(defun c:mul (/)
(setq myent (entsel))
(command "offset" pause myent pause "")
(setq newent (entget (entlast)))
(while (/= newent nil)
(command "offset" pause newent pause "")
(setq newent (entget (entlast)))
)
)


Thanks
Rick
*Alex
Message 9 of 12 (211 Views)

Re: Continuous Offset with last entity & diff dist...

06-24-2005 10:35 AM in reply to: *Rick Keller
glad to be of help. coming up with new and fatser ways to do things is a
lot of fun.


"Rick Keller" wrote in message
news:4884478@discussion.autodesk.com...
Yes Alex that is exactly what I was driving for (mvo).

Thanks for the code. What I had was working but I was going to refine it to
work
just like yours does.

Thanks again.
Rick


"Alex" wrote in message
news:4884360@discussion.autodesk.com...
This may also help. Hopefully I included all the sub routines.

; mvo multi variable offset BY ALEX KONIECZKA
(defun c:mvo ()
(print "Select object to offset: ")(gent)
(setq tpt entpt tpt1 (getpoint "Select side to offset: ") dd 0 tang (angle
entpt tpt1))


(while (setq d (getstring "Enter an offset value (*# for multiple) :"))

(if (= "*" (substr d 1 1))
(progn (setq n (atoi (substr d 2)) d (getstring "Distance: : ") d (atof
) ))
(progn (setq n 1 d (atof d) ))
) ;if

(repeat n (progn

(SETQ DD (+ DD D) tpt (polar tpt tang dd) )
(command "offset" d entn tpt "")(gents (entlast))
))

); while
(princ) )


; offset from base pick a base point and hold the cursor on the side you
want to offset and start typing #'s

(defun c:smileysurprised:b ()
(print "Select base object to offset from and put currsor on the offset
side, then type numbers: ")(gent)
(while (setq d (getstring "Enter an offset value (*# for multiple) :"))
(setq tpt1 (cadr (grread 1)))
(setq tpt entpt dd 0 tang (angle entpt tpt1))
(command "offset" d entn tpt1 "")
); while
(princ) )

; ot offset through will change layer to the picked item.
(defun c:smileysurprised:t ()
(print "Select base object to offset: ")(gent)(setq e (car entn))
(while (gent)
(setq layn (ass 8) tpt1 entpt)
(command "offset" "t" e tpt1 "")
(gents (entlast))(modent 8 layn)
); while
(princ) )



; dof = double offset to current layer

(defun c:dof ()
(setq d (getval d "Enter doffset: "))
(while (print "Select line to offset: ")(gent)
(if (= (ass 0) "LINE")(progn
(setq e entn tpt1 (polar (ass 10) (+ (angle (ass 10) (ass 11)) (/ pi 2))
1) tpt2 (polar (ass 10) (+ (angle (ass 10) (ass 11)) (/ pi -2)) 1) )
(command "offset" d e tpt1 "")(gents (entlast))(modent 8 (getvar
"clayer"))
(command "offset" d e tpt2 "")(gents (entlast))(modent 8 (getvar
"clayer"))
)))
(princ))

; gent returns the entity name of the item picked
(defun gent ()
(setq entn (entsel))
(setq entcodes (entget (car entn)))
(setq entpt (cadr entn))
(setq entt (cdr (assoc 0 entcodes)))
)

; ass returns the (cdr (assoc n)) of the the item. (ass 10) => (10 . 1 2 3)
(defun ass (code / )
(cdr (assoc code entcodes))
)

; gents returns the entity name of the item passed to it from a selction set
(defun gents (entname /)
(setq entn entname entcodes (entget entn) entpt nil)
(setq entt (cdr (assoc 0 entcodes)))
(princ))




"Rick Keller" wrote in message
news:4883417@discussion.autodesk.com...
I am trying to write a lisp routine that will offset a line then
automatically select the new line and ask for a new distance.

It is not working like I thought it would... Any Help / suggestions?

Here is what I have:

(defun c:mul (/)
(setq myent (entsel))
(command "offset" pause myent pause "")
(setq newent (entget (entlast)))
(while (/= newent nil)
(command "offset" pause newent pause "")
(setq newent (entget (entlast)))
)
)


Thanks
Rick
Member
vinodhkumar
Posts: 5
Registered: ‎06-04-2012
Message 10 of 12 (168 Views)

Re: Continuous Offset with last entity & diff dist...

06-05-2012 06:25 AM in reply to: *Alex

i want continuous doubleoffset with last entity in c#.net.please give logic

Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.