Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Contributor
taiki84
Posts: 12
Registered: ‎05-13-2014
Message 1 of 12 (169 Views)
Accepted Solution

Can you help me to correct my lisp

169 Views, 11 Replies
07-20-2014 01:08 PM

Hello

 

I have two question,

First can you help me to correct this lisp?

Second i want to add a function that convert attibutes layers to 0.

 

 

 


(defun c:clb ( / *error* om js js_all n fence js_ins nb Counter )
(princ "\nSélectionnez les polylignes: ")
(or
(setq js (ssget "_I" '((0 . "POLYLINE,LINE,LWPOLYLINE"))))
(setq js (ssget "_P" '((0 . "POLYLINE,LINE,LWPOLYLINE"))))
);or
(cond
(js
(sssetfirst nil js)
(initget "Existant Nouveau _Existent New")
(if (eq (getkword "\nTraiter jeu de sélection [Existant/Nouveau] <Existant>: ") "New")
(progn (sssetfirst nil nil) (setq js (ssadd) js (ssget)))
);js
);cond
(T
(setq js (ssget '((0 . "POLYLINE,LINE,LWPOLYLINE"))))
);t

);or
(progn
(setq js_all (ssadd)
om (getvar "attmode")
)
(setvar "attmode" 0)
(command "_regen")
(cond
(js
(repeat (setq n (sslength js))
(setq
fence (listpol (ssname js (setq n (1- n))))
js_ins (ssget "_F" fence '((0 . "INSERT")))
);setq
(cond
(js_ins

(repeat (setq nb (sslength js_ins))
(ssadd (ssname js_ins (setq nb (1- nb))) js_all)
);repat2
);ji_ins
);cond2
);repeat1
);js
);cond
(setvar "ATTMODE" om)
(command "_.REGEN")
);progn

(prompt "\nSelectioner un objet sur le calque de déstination: ")
(setq Clayer (cdr (assoc 8 (entget (car (entsel))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq Counter (- (sslength js_all) 1 ))
(while (/= Counter -1)
(setq EntList (entget (ssname js_all Counter)))
(setq EntList (subst (cons 8 Clayer)(assoc 8 EntList) EntList))
(entmod EntList)
(setq Counter (1- Counter))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq a "_POINT")
(if (sslength js_all)
(setq e (entget js_all)
x (assoc 8 e)
n (strcat (cdr x) a)
)
(entmod (subst (cons 8 n) x e))
(if (not (member n l))
(progn
(setq l (cons n l)
e (entget (tblobjname "layer" (cdr x)))
d (entget (tblobjname "layer" n))
)
(foreach k '(-1 2 5)
(setq e (subst (assoc k d) (assoc k e) e))
)
(entmod e)
)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(sssetfirst nil js_all)
(prin1)
);defun

;;; listpol by Gille Chanteau ;
;;; Returns the vertices list of any type of polyline (WCS coordinates) ;
;;; ;
;;; Argument ;
;;; en, a polyline (ename or vla-object) ;

(defun listpol (en / i p l)
(setq i
(if (vlax-curve-IsClosed en)
(vlax-curve-getEndParam en)
(+ (vlax-curve-getEndParam en) 1)
);if
);seetq i
(while (setq p (vlax-curve-getPointAtParam en (setq i (1- i))))
(setq l (cons (trans p 0 1 ) l))
);while
);defun

;; Tharwat 23.05.2014 ;;
(defun *error* (msg)
(if om
(setvar "ATTMODE" om)
)
(command "_.REGEN")
(if (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")
(princ msg)
(princ (strcat "Error : < ** " msg " ** >"))
)
)
(princ "\nchange layer blocks on polyline with or without pre-selection....loaded.")
(terpri)
(princ "command clb")
(print)

Revised [Still not sure if it works for all conditions]

*Expert Elite*
pbejse
Posts: 2,502
Registered: ‎11-24-2009
Message 2 of 12 (137 Views)

Re: Can you help me to correct my lisp

07-20-2014 10:31 PM in reply to: taiki84

taiki84 wrote:

Hello

 

I have two question,

First can you help me to correct this lisp?

Second i want to add a function that convert attibutes layers to 0. 

 

 


First, whats wrong with it? and what is it supposed to do? give us a brief description what the code is all about

Second , Attribute layers to 0 is easy

Contributor
taiki84
Posts: 12
Registered: ‎05-13-2014
Message 3 of 12 (132 Views)

Re: Can you help me to correct my lisp

07-20-2014 11:20 PM in reply to: pbejse

Sorry 

 

This lisp change layer of blocks by selection with a polyline.

Just the probleme is i want to create a layer for the selected blocks with the same name as the polyline adding a suffix and keep propriete of original layer. and convert one attribute to layer 0 and the second attribute to invisible.

 

My lisp select correctly blocks deplace on the layers of my choice, but he not add suffix.

 

And just can you give me the way to look for convert attributes.

 

Thanks a lot for your help.

*Expert Elite*
pbejse
Posts: 2,502
Registered: ‎11-24-2009
Message 4 of 12 (127 Views)

Re: Can you help me to correct my lisp

07-20-2014 11:30 PM in reply to: taiki84

If you dont mind, post a drawing file where we can test the code for better understanding

Contributor
taiki84
Posts: 12
Registered: ‎05-13-2014
Message 5 of 12 (119 Views)

Re: Can you help me to correct my lisp

07-21-2014 12:00 AM in reply to: pbejse

Two drawing "original" for test and the result.

 

thanks

*Expert Elite*
pbejse
Posts: 2,502
Registered: ‎11-24-2009
Message 6 of 12 (112 Views)

Re: Can you help me to correct my lisp

07-21-2014 12:21 AM in reply to: taiki84

Okay hang on...

 

EDIT: Cant seem to understand the logic of you're original code taiki84, I may end up writing an entirely new code. Will that be acceptable? otherwise it would take me more time trying to figure out what to change on your code.

 

Contributor
taiki84
Posts: 12
Registered: ‎05-13-2014
Message 7 of 12 (103 Views)

Re: Can you help me to correct my lisp

07-21-2014 01:18 AM in reply to: pbejse

Ok thanks for your help,

 

if you have the time to write a new code to do the same, i'll take it for undertand and change mine.

 

 

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

Re: Can you help me to correct my lisp

07-21-2014 02:00 AM in reply to: taiki84

Not sure if this modified lisp will work for you, I tried as much as possible not to deviate from your original code.

 

See attached LSP file

Contributor
taiki84
Posts: 12
Registered: ‎05-13-2014
Message 9 of 12 (93 Views)

Re: Can you help me to correct my lisp

07-21-2014 02:08 AM in reply to: pbejse

Ok that work but he don't appli the same proprieties at the new layers.

 

Thanks

*Expert Elite*
pbejse
Posts: 2,502
Registered: ‎11-24-2009
Message 10 of 12 (72 Views)

Re: Can you help me to correct my lisp

07-21-2014 06:08 AM in reply to: taiki84

Revised [Still not sure if it works for all conditions]

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!