rajeshmuthu Posted September 27, 2011 Posted September 27, 2011 Can any one help me? I need lisp for two layer changes with using OFFSET command. Please see my below sketch...Here there are two layers which are CONCRETE & COVER Layers. Now the current layer is CONCRETE, I need to offset 50mm to inside rectangle with COVER layer(Without manual changes in layer properties) but after complete offset command, the current layer shall be change to old layer which is CONCRETE Layer. Please help me.. [ATTACH=CONFIG]30228[/ATTACH] Quote
Tharwat Posted September 27, 2011 Posted September 27, 2011 This .... ? (defun c:test (/ n ss p e) ;; Tharwat 27. Sep. 2011 ;; (if (and (setq n (getdist "\n Specify the Offset Distance :")) (setq ss (ssget "_+.:S:L" '((0 . "*POLYLINE,*LINE,CIRCLE,ELLIPSE"))) ) (setq p (getpoint "\n Specify point :")) ) (progn (command "_.offset" n ss "_non" p "") (setq e (entlast)) (if (tblsearch "LAYER" "cover") (command "_.chprop" e "" "_layer" "cover" "") ) ) (princ) ) (princ) ) Tharwat Quote
Lt Dan's legs Posted September 27, 2011 Posted September 27, 2011 (defun c:test ( / ss->lst pairpts revpl coverlayer concretelayer dist ss ) (vl-load-com) (setq coverlayer "defpoints") (setq concretelayer "0") (defun ss->lst ( ss flag / id lst ) (if (eq 'PICKSET (type ss)) (repeat (setq id (sslength ss)) ( (lambda ( name ) (setq lst (cons (if flag (vlax-ename->vla-object name) name )lst ) ) )(ssname ss (setq id (1- id))) ) ) ) ) (defun pairpts ( _list / l pt ) (foreach x (reverse _list) (if pt (setq l (cons (cons x pt) l) pt nil) (setq pt (cons x pt)) ) ) l ) (defun revpl ( vla-obj / catch openpl ) (and (eq :vlax-false (setq openpl (vla-get-closed vla-obj))) (vla-put-closed vla-obj :vlax-true) ) (setq catch (vl-catch-all-apply (function vlax-invoke) (list vla-obj 'offset (vla-get-length vla-obj) ) ) ) (and (eq :vlax-false openpl) (vla-put-closed vla-obj :vlax-false) ) (if (vl-catch-all-error-p catch) (vlax-put vla-obj 'coordinates (apply (function append) (reverse (pairpts (vlax-get vla-obj 'coordinates)) ) ) ) (and catch (vla-delete (car catch))) ) vla-obj ) (if (and (setq dist (getdist "\nSpecify distance to offset: ")) (setq ss (ss->lst (ssget '((0 . "lwpolyline"))) t))) (foreach x ss (vla-put-layer x coverlayer) (vla-put-layer (car (vlax-invoke (revpl x) 'offset dist ) ) concretelayer ) ) ) (princ) ) Quote
BIGAL Posted September 28, 2011 Posted September 28, 2011 This may be usefull to add to Tharwats code http://www.cadtutor.net/forum/showthread.php?62893-LISP-for-a-rectangle-inside-a-rectangle Something combination of the two ? Quote
K Baden Posted August 31, 2017 Posted August 31, 2017 What about presetting the offset to 3'-0", for a selected set of objects that need offset, and instead of changing the layer of the new offset line, change the LineType to DASHDOT? Quote
BIGAL Posted August 31, 2017 Posted August 31, 2017 (edited) K Baden have a look at these bits of code from above it has all the answers you seek, good time to try out your lisp skills. (setq dist (vla-put-layer look at 2nd one Edited September 1, 2017 by BIGAL Quote
K Baden Posted September 1, 2017 Posted September 1, 2017 (edited) This is what i came up with. I keep getting a Malformed List on input error when loading and im not sure why. do i need to surround everything with "(progn)"? I'm using the _:L selection because it lets me select multiple objects. I've read through the options with that and I'm having a hard time telling if that's the best one to use. Diving into the second code given here using ActiveX (right? lol) is a bit over my head yet. EDIT: also, will the entlast selection grab the new offset line from multiple selections? say i offset 6 rectangle polylines, I would want it to grab every new offset line and change the linetype. Perhaps the use of ActiveX code is necessary for this application. Realistically, what im shooting for is the only user intervention necessary with this command will be selecting the objects. (defun c:GPOFF (/ ss e) (setq ss (ssget "_:L") (command "_.offset" "3'-0" ss "_non" "0,0" "") (setq e (entlast)) (command "_.chprop" e "" "_LTYPE" "DASHDOT" "") (princ) ) Edited September 1, 2017 by K Baden Quote
hanhphuc Posted September 1, 2017 Posted September 1, 2017 This is what i came up with. I keep getting a Malformed List on input error when loading and im not sure why common error missing bracket "(" ")" search keyword "vla-offset" simple example by Tharwat Quote
K Baden Posted September 1, 2017 Posted September 1, 2017 Thank you! this got the command working, but it unfortunately only offsets the last rectangle selected. I am assuming this is because im using just the command callout. Back to the drawing board! (defun c:GPOFF ( / ss e) (setq ss (ssget "_:L")) (command "_.offset" "3'" ss "_non" "0,0" "") (setq e (entlast)) (command "_.chprop" e "" "_LTYPE" "DASHDOT" "") (princ) ) Quote
K Baden Posted September 1, 2017 Posted September 1, 2017 I've made some progress! I have it doing exactly what i want, but it is changing the original selected lines to DASHDOT as well as the newly created offset lines. Looking at this, i'm having a hard time understanding what, if any, variable refers to the new lines that have been created. anyone have any advice? (defun c:test ( / ss->lst pairpts revpl dist ss ) (vl-load-com) (defun ss->lst ( ss flag / id lst ) (if (eq 'PICKSET (type ss)) (repeat (setq id (sslength ss)) ( (lambda ( name ) (setq lst (cons (if flag (vlax-ename->vla-object name) name )lst ) ) )(ssname ss (setq id (1- id))) ) ) ) ) (defun pairpts ( _list / l pt ) (foreach x (reverse _list) (if pt (setq l (cons (cons x pt) l) pt nil) (setq pt (cons x pt)) ) ) l ) (defun revpl ( vla-obj / catch openpl ) (and (eq :vlax-false (setq openpl (vla-get-closed vla-obj))) (vla-put-closed vla-obj :vlax-true) ) (setq catch (vl-catch-all-apply (function vlax-invoke) (list vla-obj 'offset (vla-get-length vla-obj) ) ) ) (and (eq :vlax-false openpl) (vla-put-closed vla-obj :vlax-false) ) (if (vl-catch-all-error-p catch) (vlax-put vla-obj 'coordinates (apply (function append) (reverse (pairpts (vlax-get vla-obj 'coordinates)) ) ) ) (and catch (vla-delete (car catch))) ) vla-obj ) (if (and (setq dist (distance '(0.0 0.0) '(36.0 0.0))) (setq ss (ss->lst (ssget '((0 . "lwpolyline"))) t))) (foreach x ss (vla-put-linetype x "DASHDOT") (car (vlax-invoke (revpl x) 'offset dist ) ) ) ) (princ) ) Quote
ronjonp Posted September 1, 2017 Posted September 1, 2017 I've made some progress! I have it doing exactly what i want, but it is changing the original selected lines to DASHDOT as well as the newly created offset lines. Looking at this, i'm having a hard time understanding what, if any, variable refers to the new lines that have been created. anyone have any advice? (defun c:test ( / ss->lst pairpts revpl dist ss ) (vl-load-com) (defun ss->lst ( ss flag / id lst ) (if (eq 'PICKSET (type ss)) (repeat (setq id (sslength ss)) ( (lambda ( name ) (setq lst (cons (if flag (vlax-ename->vla-object name) name )lst ) ) )(ssname ss (setq id (1- id))) ) ) ) ) (defun pairpts ( _list / l pt ) (foreach x (reverse _list) (if pt (setq l (cons (cons x pt) l) pt nil) (setq pt (cons x pt)) ) ) l ) (defun revpl ( vla-obj / catch openpl ) (and (eq :vlax-false (setq openpl (vla-get-closed vla-obj))) (vla-put-closed vla-obj :vlax-true) ) (setq catch (vl-catch-all-apply (function vlax-invoke) (list vla-obj 'offset (vla-get-length vla-obj) ) ) ) (and (eq :vlax-false openpl) (vla-put-closed vla-obj :vlax-false) ) (if (vl-catch-all-error-p catch) (vlax-put vla-obj 'coordinates (apply (function append) (reverse (pairpts (vlax-get vla-obj 'coordinates)) ) ) ) (and catch (vla-delete (car catch))) ) vla-obj ) (if (and (setq dist (distance '(0.0 0.0) '(36.0 0.0))) (setq ss (ss->lst (ssget '((0 . "lwpolyline"))) t))) (foreach x ss (vla-put-linetype x "DASHDOT") (car (vlax-invoke (revpl x) 'offset dist ) ) ) ) (princ) ) Change to this: (foreach x ss (vla-put-linetype (car (vlax-invoke (revpl x) 'offset dist)) "DASHDOT")) BTW .. you should check that DASHDOT is loaded or the program will fail. Quote
logandee Posted July 15 Posted July 15 On 27/09/2011 at 07:33, Tharwat said: This .... ? (defun c:test (/ n ss p e) ;; Tharwat 27. Sep. 2011 ;; (if (and (setq n (getdist "\n Specify the Offset Distance :")) (setq ss (ssget "_+.:S:L" '((0 . "*POLYLINE,*LINE,CIRCLE,ELLIPSE"))) ) (setq p (getpoint "\n Specify point :")) ) (progn (command "_.offset" n ss "_non" p "") (setq e (entlast)) (if (tblsearch "LAYER" "cover") (command "_.chprop" e "" "_layer" "cover" "") ) ) (princ) ) (princ) ) Tharwat I have been using your code here Tharwat for some time but wondered if it could be modified to remember last input from previous uses of the command during the current session? I am currently going through the beginning stages of learning AutoLISP but so far this is above my understanding (long way to go!). Quote
Tharwat Posted July 16 Posted July 16 Here's an example and hopefully there's not any issue because I am typing from Mobile. (or *offset* (setq *offset* 1.0)) (cond ((getdist (strcat "\nSpecify Offset Distance < " (itoa *offset*) " > : "))) (*offset*)) 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.