Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Active Contributor
weedseed85
Posts: 33
Registered: ‎02-05-2013
Message 1 of 8 (283 Views)
Accepted Solution

Debugging my Lisp

283 Views, 7 Replies
02-18-2013 12:32 AM

Dear Autocad / Lisp users,

Could somebody please help me with my lisp.

The main goal for the lisp is to correct all colors of the given layers.
And for a few exceptions I want to change the LineType and set them to ByLayer.

It works, most of the time. But it always gives errors.

Couls somebody please have a look?

 

(defun c:SLC8 ()
	(setq kleur 8)
	(ChangeLayerColor kleur)
	
)
(defun ChangeLayerColor (kleur / sset ename i)
	(vl-load-com)
	(setq i 0)
	(setq sset (ssget "X" '((8 . "AL*"))))
		(if sset
			(repeat (sslength sset)
				(setq ename (ssname sset i))
				(setq i (1+ i))
				(vla-put-color (vlax-ename->vla-object ename) kleur)
			)
		)
	(setvar "cmdecho" 0)
	(command "-layer" "unlock" "*" "")
	(command "layer" "c" "7" "0" "")
	(command "layer" "c" "7" "*AL70----*" "")
	(command "layer" "c" "1" "*AL-----_VLOERPLAAT" "")
	(command "layer" "c" "2" "*AL-----_SPARING" "")
	(command "layer" "c" "1" "*AL_MAATVOERING" "")
	(command "layer" "c" "8" "*AL31----*" "")
	(command "layer" "c" "8" "*AL32----*" "")
	(command "layer" "c" "8" "*AL21----*" "")
	(command "layer" "c" "8" "*AL22----*" "")
	(command "layer" "c" "8" "*AL_31----*" "")
	(command "layer" "c" "8" "*AL_32----*" "")
	(command "layer" "c" "8" "*AL_21----*" "")
	(command "layer" "c" "8" "*AL_22----*" "")
	
	(command "layer" "c" "8" "*AT$1A---_TEKST012" "")
	(command "layer" "c" "8" "*AT$1A---_TEKST018" "")
	(command "layer" "c" "8" "*AT$1A---_TEKST025" "")
	(command "layer" "c" "8" "*AT$1A---_TEKST035" "")
	(command "layer" "c" "8" "*AT$1A---_TEKST050" "")
	(command "layer" "c" "8" "*AT$1A---_TEKST070" "")
	(command "layer" "c" "8" "*AT$1A---_TEKST100" "")
	
	(command "layer" "c" "1" "ATT012*" "")
	(command "layer" "c" "1" "ATT018*" "")
	(command "layer" "c" "2" "ATT025*" "")
	(command "layer" "c" "3" "ATT035*" "")
	(command "layer" "c" "4" "ATT050*" "")
	(command "layer" "c" "5" "ATT070*" "")
	(command "layer" "c" "6" "ATT100*" "")
	
	(command "layer" "c" "254" "00ATT018*" "")
	(command "layer" "c" "254" "00ATT025*" "")
	(command "layer" "c" "254" "00ATT035*" "")
	(command "layer" "c" "254" "00ATT050*" "")
	(command "layer" "c" "254" "00ATT070*" "")
	(command "layer" "c" "254" "00ATT100*" "")
	
	(command "layer" "c" "254" "00KAD018*" "")
	(command "layer" "c" "254" "00KAD025*" "")
	(command "layer" "c" "254" "00KAD035*" "")
	(command "layer" "c" "254" "00KAD050*" "")
	(command "layer" "c" "254" "00KAD070*" "")
	(command "layer" "c" "254" "00KAD100*" "")
	
	(command "layer" "c" "7" "0" "")
	(command "layer" "c" "254" "*BL$2----*" "")
	(command "layer" "c" "1" "*BL$3----*" "")
	(command "layer" "c" "254" "*BL$4----*" "")
	(command "layer" "c" "254" "*BL$5----*" "")
	(command "layer" "c" "254" "*BL$6----*" "")
	(command "layer" "c" "8" "*BL$7----*" "")
	(command "layer" "c" "8" "*BM$7----*" "")
	(command "layer" "c" "7" "*BL$9----*" "")
	(command "layer" "c" "7" "*FL80----" "")
	(command "layer" "c" "8" "*WL905---*" "")
	(command "layer" "c" "8" "*Xref*" "")
	(command "layer" "c" "8" "*BL$8----_TEKST*" "")
	(command "layer" "c" "8" "*BT$8----*" "")
	
	(command "SETBYLAYERMODE" "1" "")
	(command "clayer" "0")

	(command "SETBYLAYERMODE" "99" "")
	(command "layer" "c" "8" "*BL$7----*" "Ltype" "DASHDOT" "*BL$7----*" "")
	(command "._setbylayer" (ssget "X" (list (cons 8 "*BL$7----*"))) "" "yes" "yes")
	
	
	(if (tblsearch "LAYER" "BL$8----")
			(command "layer" "c" "1" "*BL$8----*" "Plot" "No" "BL$8----*" "" "")
	(princ "\nLaag BL$8---- Niet kunnen vinden")
	)
	(princ)

	(if (tblsearch "LAYER" "BL$8----Verdieping")	
			(command "layer" "c" "1" "*BL$8----Verdieping*" "Plot" "No" "*BL$8----Verdieping*" "" "")
	(princ "\nLaag BL$8----Verdieping Niet kunnen vinden")
)
	(princ)

	(if (tblsearch "LAYER" "FL------_BWS30")
		(progn
			(command "._setbylayer" (ssget "X" (list (cons 8 "FL------_BWS30"))) "" "yes" "yes" "")
			(command "layer" "c" "14" "*FL------_BWS30" "")
			(command "_draworder" (ssget "X" (list (cons 8 "FL------_BWS30"))) "" "Front" "")
		)
		(princ "\nLaag FL------_BWS30 Niet kunnen vinden")
	)
	(princ)

	(if (tblsearch "LAYER" "FL------_BWS60")
		(progn
			(command "._setbylayer" (ssget "X" (list (cons 8 "FL------_BWS60"))) "" "yes" "yes" "")
			(command "layer" "c" "90" "*FL------_BWS60" "")
			(command "_draworder" (ssget "X" (list (cons 8 "FL------_BWS60"))) "" "Front" "")
		)
		(princ "\nLaag FL------_BWS60 Niet kunnen vinden")
	)
	(princ)
)
(princ)

 


Any help will be great.
Thanks in advance.

Michel

You're welcome, Michel
Glad I could help

 

Henrique

*Expert Elite*
hmsilva
Posts: 3,369
Registered: ‎12-17-2004
Message 2 of 8 (277 Views)

Re: Debugging my Lisp

02-18-2013 01:19 AM in reply to: weedseed85

Michel,
some of the things I saw in your code:

 

(defun c:SLC8 ()
	(setq kleur 8)
	(ChangeLayerColor kleur)
	
;)<--You are close the "SLC8" function in
(defun ChangeLayerColor (kleur / sset ename i)
	(vl-load-com)
	(setq i 0)
...
...
)
(princ)
);<--should be here

 

you should test the existence of layer before using the command layer, because there are no layer with that name will give some error
you are using several "princ \ n" without any need, you can just use "prompt \ n".

 

(if (tblsearch "LAYER" "BL$8----");<--You are testing the existence of a ayer with this exact name
    (command "_.layer" "c" "1" "*BL$8----*" "Plot" "No" "BL$8----*" "" "");<--and change "*BL$8----*" and "BL$8----*" , they exist???
    (prompt "\nLaag BL$8---- Niet kunnen vinden")
)

 

Hope that helps, good luck

 

Henrique

*Expert Elite*
hmsilva
Posts: 3,369
Registered: ‎12-17-2004
Message 3 of 8 (262 Views)

Re: Debugging my Lisp

02-18-2013 01:57 AM in reply to: weedseed85

Michel,
I made some changes in your code, test the attached code, and see if it gives error


Henrique

Active Contributor
weedseed85
Posts: 33
Registered: ‎02-05-2013
Message 4 of 8 (249 Views)

Re: Debugging my Lisp

02-18-2013 03:33 AM in reply to: hmsilva

Dear Henrique,

 

Thank you verry, verry much for your help.

 

I'll give the "updated" lisp a go and let you know.

 

Greets,

Michel

Active Contributor
weedseed85
Posts: 33
Registered: ‎02-05-2013
Message 5 of 8 (239 Views)

Re: Debugging my Lisp

02-18-2013 04:37 AM in reply to: weedseed85

Dear Henrique,

 

I've tested the lisp you provided. 

 

Unfortunaly is doesn't correct all the layer colors, like I want it to do. 

No matter tho. I can use the lisp to update my lisp annyway.

 

I'll might even learn a thing or 2..3.. or even more :smileyvery-happy:

 

Thank you verry much for your help.

 

Greets,

Michel

*Expert Elite*
hmsilva
Posts: 3,369
Registered: ‎12-17-2004
Message 6 of 8 (235 Views)

Re: Debugging my Lisp

02-18-2013 04:40 AM in reply to: weedseed85

You're welcome, Michel
Glad I could help

 

Henrique

*Expert Elite*
Kent1Cooper
Posts: 5,879
Registered: ‎09-13-2004
Message 7 of 8 (212 Views)

Re: Debugging my Lisp

02-18-2013 05:54 AM in reply to: weedseed85

weedseed85 wrote:
....
The main goal for the lisp is to correct all colors of the given layers.
.... 
....
(command "layer" "c" "7" "0" "") ....;;;; 52 similar lines ....
(command "layer" "c" "8" "*BT$8----*" "") ....

....


For the color assignment part, people who didn't originally learn to work with Layers by the Command:-line Layer command may not be aware of some of its operational possibilities.  You can combine multiple Layer options within one Layer command.  And you can assign most Layer options, such as Color, to more than one Layer at a time, using comma-separated Layer names.  And in Layer options like that, if a stated Layer name doesn't exist, a message will go by that it didn't find it, and it will return to the Layer sub-prompt, but it won't cause any error, which means it's not necessary to check whether a Layer exists as hmsilva's routine does -- if it exists, it will get the color assigned to it, but if it doesn't, it won't matter.  And as to AutoLISP, you can combine multiple commands within one (command) function, but since you can combine multiple Layer options in one Layer command, that becomes irrelevant to this part of the routine.

 

The unlocking of all Layers and the 54 Layer-color assignment lines can be combined into one (command) function containing one Layer command, containing just one Color option for every color used, rather than a separate (command) function and Layer command and Color option for every Layer name category.  Hoping that my copying and pasting of Layer name categories and deletions of excess stuff are done correctly throughout, this should do it:

 

(command "_.layer"

  "unlock" "*"
  "c" "7" "0,*AL70----*,*BL$9----*.*FL80----"
  "c" "1" "*AL-----_VLOERPLAAT,*AL_MAATVOERING,ATT012*,ATT018*,*BL$3----*"
  "c" "2" "*AL-----_SPARING,ATT025*"
  "c" "8" "*AL31----*,*AL32----*,*AL21----*,*AL22----*,*AL_31----*,*AL_32----*,*AL_21----*,*AL_22----*,*AT$1A---_TEKST012,*AT$1A---_TEKST018,*AT$1A---_TEKST025,*AT$1A---_TEKST035,*AT$1A---_TEKST050,*AT$1A---_TEKST070,*AT$1A---_TEKST100,*BL$7----*,*BM$7----*,*WL905---*,*Xref*,*BL$8----_TEKST*,*BT$8----*"
  "c" "3" "ATT035*"

  "c" "4" "ATT050*"
  "c" "5" "ATT070*"

  "c" "6" "ATT100*"
  "c" "254" "00ATT018*,00ATT025*,00ATT035*,00ATT050*,00ATT070*,00ATT100*,00KAD018*,00KAD025*,00KAD035*,00KAD050*,00KAD070*,00KAD100*,*BL$2----*,*BL$4----*,*BL$5----*,*BL$6----*"

  "" ; finish Layer command

); end command function

 

And I wonder whether you could go even further.  If there are no Layers outside the coverage of the routine that start with *AL3... or *AL2... or *AT$1A... but that you do not want to have color 8 assigned to them, and if there are none that start with 00... but that you do not want to have color 254 assigned to them, then you can simplify it to this:

 

(command "_.layer"

  "unlock" "*"

  "c" "7" "0,*AL70----*,*BL$9----*.*FL80----"

  "c" "1" "*AL-----_VLOERPLAAT,*AL_MAATVOERING,ATT012*,ATT018*,*BL$3----*"

  "c" "2" "*AL-----_SPARING,ATT025*"

  "c" "8" "*AL3*,*AL2*,*AT$1A*,*BL$7----*,*BM$7----*,*WL905---*,*Xref*,*BL$8----_TEKST*,*BT$8----*"

  "c" "3" "ATT035*"

  "c" "4" "ATT050*"

  "c" "5" "ATT070*"

  "c" "6" "ATT100*"

  "c" "254" "00*,*BL$2----*,*BL$4----*,*BL$5----*,*BL$6----*"

  "" ; finish Layer command

); end command function

 

Similarly, you can assign the same Plot status to multiple Layers at once, and you don't need to check whether they exist in the drawing to do it.  I'll leave you to do such further consolidations.

Kent Cooper
*Expert Elite*
hmsilva
Posts: 3,369
Registered: ‎12-17-2004
Message 8 of 8 (204 Views)

Re: Debugging my Lisp

02-18-2013 07:04 AM in reply to: Kent1Cooper

Kent1Cooper wrote:
people who didn't originally learn to work with Layers by the Command:-line Layer command may not be...
...

Kent,
oops, my bad, is not my case...
I started working with the ACr10, with the firts pull-down menus, almost always used the command line versions of the commands,
so I was obliged to remember that the -layer command can be combined into one (command) function, without giving error...
Thank you for this fix, that will force me to correct a code that I had done, and I will make this code much lighter.
Hopefully I will not forget ... :smileywink:


Cheers

Henrique

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.