Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor lai
Distinguished Contributor
lai
Posts: 123
Registered: ‎08-15-2011
Message 1 of 11 (1,004 Views)
Accepted Solution

Auto offset for selected items

1004 Views, 10 Replies
01-25-2013 12:55 AM

I wish to have a lisp than enable to do automatic offset base on some selection of lines ,circles or polylines object as shown in attachment. Does anyone have idea on it?


lai wrote:

I wish to have a lisp than enable to do automatic offset base on some selection of lines ,circles or polylines object as shown in attachment. Does anyone have idea on it?


 

(defun c:osd ( / ss e )
(setq ofd (cond
((getdist (strcat "\nEnter Offset distance"
(if ofd (strcat " <" (rtos ofd) ">: ") ": ")
)))(ofd))
)
(if (setq ss (ssget ":L"))
(repeat (sslength ss)
(setq e (vlax-ename->vla-object (ssname ss 0)))
(if (vlax-method-applicable-p e 'Offset)
(mapcar '(lambda (o)
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-offset (list e o))))(list ofd (- ofd)))
)
(ssdel (ssname ss 0) ss)))
(princ)
)

 

HTH

 


lai wrote:

Hi pbejse,

I not sure if the lisp can be modify to do it to be as shown in attachment.


But of course

 

(defun c:osdc ( / ss e )
(setq ofd (cond
((getdist (strcat "\nEnter Offset distance"
(if ofd (strcat " <" (rtos ofd) ">: ") ": ")
)))(ofd))
)
(if (setq ss (ssget ":L"))
(repeat (sslength ss)
(setq e (vlax-ename->vla-object (ssname ss 0)))
(if (vlax-method-applicable-p e 'Offset)
(progn
(mapcar '(lambda (o)
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-offset (list e o))))(list ofd (- ofd)))
  (mapcar '(lambda (p)
(entmakex (list (cons 0 "CIRCLE")
(cons 10 p)
(cons 40 ofd))))
(list (vlax-curve-getstartpoint e)
(vlax-curve-getendpoint e)))
)
)
(ssdel (ssname ss 0) ss)))
(princ)
)

 

command: Osdc

Select objects:

 

HTH

 

*Expert Elite*
hmsilva
Posts: 2,903
Registered: ‎12-17-2004
Message 2 of 11 (989 Views)

Re: Auto offset for selected items

01-25-2013 03:50 AM in reply to: lai

lai wrote:
I wish to have a lisp than enable to do automatic offset base on some selection of lines ,circles or polylines object as shown in attachment. Does anyone have idea on it?

 

perhaps something like

 

(defun c:test (/ dist ent curve pt1 pt2 pt3 pt4)
  (vl-load-com)
  (setq dist (getdist (strcat"\nEnter Distance to Offset: <" (rtos (getvar "offsetdist") 2 2 ) ">:")))
  (if (not dist) (setq dist (getvar "offsetdist"))); end if
  (setq ent (entsel "\nSelect Object to Offset:"))
  (setq curve (vlax-ename->vla-object (car ent)))
  (setq pt1 (vlax-curve-getClosestPointTo curve (cadr ent)))
  (setq pt2 (vlax-curve-getPointAtDist curve 0.01))
  (setq pt3 (polar pt1 (+ (angle pt1 pt2) (* pi 0.5)) 1))
  (setq pt4 (polar pt1 (- (angle pt1 pt2) (* pi 0.5)) 1))
  (command "_.offset" dist (car ent) (osnap pt3 "_non") "")
  (command "_.offset" dist (car ent) (osnap pt4 "_non") "")
  (princ)
  )

 

Hope that helps

 

Henrique

*Expert Elite*
pbejse
Posts: 2,500
Registered: ‎11-24-2009
Message 3 of 11 (980 Views)

Re: Auto offset for selected items

01-25-2013 04:52 AM in reply to: lai

lai wrote:

I wish to have a lisp than enable to do automatic offset base on some selection of lines ,circles or polylines object as shown in attachment. Does anyone have idea on it?


 

(defun c:osd ( /  ss e )
(setq ofd (cond
((getdist (strcat "\nEnter Offset distance"
 (if ofd (strcat " <" (rtos ofd) ">: ") ": ")
            )))(ofd))
)
(if (setq ss (ssget ":L"))
  (repeat (sslength ss)
          	(setq e (vlax-ename->vla-object (ssname ss 0)))
    		(if (vlax-method-applicable-p e 'Offset)
                    (mapcar '(lambda (o)
				(vl-catch-all-error-p
				  (vl-catch-all-apply
				    'vla-offset (list e o))))(list ofd (- ofd)))
                  )
    	(ssdel (ssname ss 0) ss)))
(princ)
)

 

HTH

 

*Expert Elite*
hmsilva
Posts: 2,903
Registered: ‎12-17-2004
Message 4 of 11 (974 Views)

Re: Auto offset for selected items

01-25-2013 05:10 AM in reply to: pbejse

pbejse,
very nice approach!

 

Cheers
Henrique

*Expert Elite*
Kent1Cooper
Posts: 5,539
Registered: ‎09-13-2004
Message 5 of 11 (964 Views)

Re: Auto offset for selected items

01-25-2013 05:29 AM in reply to: lai

lai wrote:

I wish to have a lisp than enable to do automatic offset base on some selection of lines ,circles or polylines object as shown in attachment. Does anyone have idea on it?


Here's my version from a couple of years ago.  It remembers the offset distance used in it, separately from regular Offset's setting, and offers it as a default on subsequent use.  But if there hasn't been a value used in it yet, it offers regular Offset's setting as a default [provided it's not Through, which would be inapplicable].

 

If you put Offset Both Sides or something similar in the Search window, you'll find a variety of threads on the subject [including one with an earlier version of the attached].

 

If you want to select all objects to Offset both ways at once, instead of one at a time, it could certainly be adjusted to do that.

Kent Cooper
*Expert Elite*
pbejse
Posts: 2,500
Registered: ‎11-24-2009
Message 6 of 11 (964 Views)

Re: Auto offset for selected items

01-25-2013 05:33 AM in reply to: hmsilva

hmsilva wrote:

pbejse,
very nice approach!

 

Cheers
Henrique


Thank you Henrique, its from an old routine of mine. Glad you like it.

 

Cheers

 

 

Distinguished Contributor lai
Distinguished Contributor
lai
Posts: 123
Registered: ‎08-15-2011
Message 7 of 11 (939 Views)

Re: Auto offset for selected items

01-25-2013 05:26 PM in reply to: hmsilva

Dear Henrique,

Thanks for your help..after test, i feel that it lack of some feature..

 

More prefer to pbejse lisp..Works more better.

*Expert Elite*
pbejse
Posts: 2,500
Registered: ‎11-24-2009
Message 8 of 11 (932 Views)

Re: Auto offset for selected items

01-25-2013 08:55 PM in reply to: lai

Glad it helps

 

Cheers :smileyhappy:

 

*Expert Elite*
hmsilva
Posts: 2,903
Registered: ‎12-17-2004
Message 9 of 11 (925 Views)

Re: Auto offset for selected items

01-26-2013 05:32 AM in reply to: lai

lai wrote

: ...

More prefer to pbejse lisp..Works more better.

 

 

I fully agree with you, pbejse's code is a great code.

 

 

Cheers

Henrique

Distinguished Contributor lai
Distinguished Contributor
lai
Posts: 123
Registered: ‎08-15-2011
Message 10 of 11 (882 Views)

Re: Auto offset for selected items

01-27-2013 09:34 PM in reply to: pbejse

Hi pbejse,

I not sure if the lisp can be modify to do it to be as shown in attachment.

Need installation help?

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