Lisp for predefined quick select options then change color

Lisp for predefined quick select options then change color

Anonymous
Not applicable
3,767 Views
13 Replies
Message 1 of 14

Lisp for predefined quick select options then change color

Anonymous
Not applicable

Hi yall,

 

First off I want to make a multi step lisp that will use the command "qselect" and i have no idea where to start after... (command "qselect"...... 

I want so select everything in the drawing whether qselect is used or not i dont know but the options i need in qselect are... (apply to entire drawing, change object type to polyline, change properties to closed, and change value to no.) 

After that i want to use (command "change" "" "P" "C" "CO" "DIC COLOR GUIDE(R) PART II" "DIC 2630" "") and even this seems not to work.... 

any help is much appreciated!!!  

 

 

thanks everyone 

0 Likes
Accepted solutions (2)
3,768 Views
13 Replies
Replies (13)
Message 2 of 14

cadffm
Consultant
Consultant
Accepted solution

QSELECT is available only as dialog window version, you can not use it (only by user input),

same with command FILTER. In Fullversions with Expresstools you have SSX for commandline selection.

 

In Lisp you can create a selectionset with SSGET , the filter based on DXF information, check Help, DXF and check object properties with (entget(car(entsel))'("*")) to find what you want.

 

But this case is a bit harder as beginner, try this

 

(if (setq Sel (ssget "_X" (list'(0 . "*POLYLINE")'(-4 . "&=")'(70 . 1)(cons 410 (getvar 'CTAB)))))
    (command "_.chprop" Sel "" "_color" "_colorbook" "DIC COLOR GUIDE(R) PART II" "DIC 2630" "")
)

 

 

Sebastian

0 Likes
Message 3 of 14

ВeekeeCZ
Consultant
Consultant

Removed by the user.

Message 4 of 14

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

.... change object type to polyline, change properties to closed, and change value to no....


 

If you want the value of the Closed property in QSELECT to be set to no, that means open Polylines only@cadffm's is built to find closed  ones only.  I suggest this modification [minimally tested, and without your Colorbook]:

(if
  (setq Sel
    (ssget "_X"
      (list
        '(0 . "*POLYLINE")
        '(-4 . "<NOT") '(-4 . "&=") '(70 . 1) '(-4 . "NOT>")
; open ones only [the (70 . 1) is about being closed] (cons 410 (getvar 'CTAB)) ; [because editing commands don't see things in other than the current space] ); list ); ssget ); setq (command "_.chprop" Sel "" "_color" "_colorbook" "DIC COLOR GUIDE(R) PART II" "DIC 2630" "") )

If you really want to change all in the drawing, not just in the current space, that would involve stepping through the selection and doing the color change with other methods than a CHPROP [or CHANGE with the Properties option] command, such as (subst)/(entmod) methods, or through VLA properties.  I don't know whether Colorbook colors can be applied in those ways, but if not, it could be made to get into the space where each Polyline is, and change its color there as above.

 

Kent Cooper, AIA
Message 5 of 14

Anonymous
Not applicable

This is awesome to know thank you so much! This also brings a whole new understanding to the world of lisp for me. I am desperately trying to learn all of it on my own because no one teaches it that i know of... if there is any thing you have to suggest for me to read or watch to help in my journey that would be awesome! 

thanks

0 Likes
Message 6 of 14

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... if there is any thing you have to suggest for me to read or watch ....


 

[Search this Forum for terms like "learn Lisp" or "Lisp tutorials" or "training" [including variants using the full word AutoLisp], and you'll find more suggestions than you can ever look into.]

Kent Cooper, AIA
0 Likes
Message 7 of 14

Anonymous
Not applicable

Here is another on for yall,

 

i then created this but i cant seen to finish it and make it work. Can anyone check my work and tell me what i need to do to fix this and combine all of it 

 

 

(defun C:STEP1()
(command "layfrz"); freez how ever many and what ever layers i want then proceed to join all geometry
(command "pedit" "multiple" "all" "" "Y" "join" "0.0000" "")
(if (setq Sel (ssget "_X" (list'(0 . "*POLYLINE")'(-4 . "&=")'(70 . 1)(cons 410 (getvar 'CTAB)))))
(command "_.chprop" Sel "" "_color" "_colorbook" "DIC COLOR GUIDE(R) PART II" "DIC 2630" "")


(defun C:STEP2()
(setq timesexplode 10)
(repeat timesexplode
(setvar "qaflags" 1)
(command ".explode" (ssget "_X" ) "")
(setvar "qaflags" 0)); explode 10 times (found this on the forums...
(command "_change""_all""""p""e""0""");puts all 2d geometry on elevation 00
(command "-overkill" "all" "" "done");overkill all
(command "-purge" "all" "" "no");purge all
(alert "Don't forget to check over your work once more.")
(command "laythw")
)))

 

0 Likes
Message 8 of 14

dbhunia
Advisor
Advisor

Hi,

 

I think you want to create two command "STEP1" (It's Joining all) & "STEP2" (It's Exploding all), if so then.......

 

 

For command "STEP1"

 

You can not use "layfrz" like this way "(command "layfrz")" within a code ...... it will give error....

 

Try this way to "Freeze" the picked layer.....(Blue one)

 

(defun C:STEP1()
  (setq CLay (getvar "CLAYER"))
  (princ "\nSelect object on layer to freeze Or press enter to end (layfrz) command & move to next..")
  (while (setq EntName (car (entsel)))
      (setq EntList (entget EntName))
      (setq Lay (cdr (assoc 8 EntList)))
      (if (and (= Lay CLay)(/= Lay "0"))
        (command ".LAYER" "T" "0" "U" "0" "ON" "0" "S" "0" "")
      )
      (if (= Lay "0")
        (princ "\nCannot freeze layer 0.")
        (command ".LAYER" "F" Lay "")
      )
  );while
(command "pedit" "multiple" "all" "" "Y" "join" "0.0000" "")
(if (setq Sel (ssget "_X" (list'(0 . "*POLYLINE")'(-4 . "&=")'(70 . 1)(cons 410 (getvar 'CTAB)))))
(command "_.chprop" Sel "" "_color" "_colorbook" "DIC COLOR GUIDE(R) PART II" "DIC 2630" "")
)
)

 

 

For command "STEP2"

 

You can not use "overkill" like this way "(command "-overkill" "all" "" "done")" within a code ...... it will give a message "Command: -overkill Unknown command "-OVERKILL". Press F1 for help."...

 

Try this way to "overkill" .....(Blue one)

 

(defun C:STEP2()
(setq timesexplode 10)
(repeat timesexplode
   (setvar "qaflags" 1)
   (command ".explode" (ssget "_X" ) "")
   (setvar "qaflags" 0)
); explode 10 times (found this on the forums...
(command "_change""_all""""p""e""0""");puts all 2d geometry on elevation 00
(load "overkillsup")
(acet-overkill2 (list (ssget "X") 0.000001 nil nil nil nil))
(command "-purge" "all" "" "no");purge all
(alert "Don't forget to check over your work once more.")
(command "laythw")
)

To find out more about overkill check this.....

https://forums.autodesk.com/t5/autocad-forum/how-do-i-call-overkill-in-a-lisp-function/td-p/2185688


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 9 of 14

ВeekeeCZ
Consultant
Consultant

Little simplified, some things changed to its benefit... It's working like this on my side.

It would be helpful to see some sample of your real drawing.

 

(defun c:STEP1 (/ ss)
  (command-s "_.LAYFRZ")
  (initcommandversion)
  (command "_.JOIN" "_All" "")
  (if (setq ss (ssget "_X" (list '(0 . "*POLYLINE") '(-4 . "&=") '(70 . 1) (cons 410 (getvar 'CTAB)))))
    (command "_.CHPROP" ss "" "_color" "_colorbook" "DIC COLOR GUIDE(R) PART II" "DIC 2630" ""))
  (princ)
)

(defun C:STEP2 ()
  (repeat 10
    (initcommandversion)
    (command "_.EXPLODE" "_All" ""))
  (command "_.CHANGE" "_all" "" "_p" "_e" 0 "") ;puts all 2d geometry on elevation 00
  (command "_.-OVERKILL" "_all" "" "_done");overkill all
  (command "_.-PURGE" "_all" "" "_no");purge all
  (alert "Don't forget to check over your work once more.")
  (command "_.LAYTHW")
  (princ)
)
0 Likes
Message 10 of 14

Anonymous
Not applicable

Here is a sample of what I have to do. I want to be able to isolate the layer I want to work with and this definitely works awesome on my end as well. If I would be able to add one thing to it, that would be to select a layer to set as current at the beginning so you can turn all other layers off and then a laythw at the end but otherwise it is amazing!  So step1 will be ran 2 or 3 times based on what i am working with, on this sample I have 2 layers to work with (the substrate and the medium layers). Ill isolate the medium layer, join and connect the corners if there is any messed up, then do the some for the substrate layer. 

 

So before, I had wrote something that worked but wasn't as complex but in it I had (command "explode" "all" "") and also tried using (command "-explode" "all" "") now it did work for me but then the next day it wouldn't work again not alone or in the routine. I just tried to entered it again and using the

(command "_.EXPLODE" "_All" "")

as well by copying and pasting and it still doesn't work the command line is saying it is an unknown command. The explode command you have supplied does work as the whole routine though. Is there any idea as to why this would be happening? ( Don't know if this changes the way you answer that but I am entering everything through VLISP...)

0 Likes
Message 11 of 14

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

... in it I had (command "explode" "all" "") and also tried using (command "-explode" "all" "") now it did work for me but then the next day it wouldn't work again ....


 

For some inexplicable reason, when inside an AutoLisp (command) function, the EXPLODE command cannot Explode multiple objects -- only one.  The simplest way to achieve that [there are others] is to precede the (command) function with (initcommandversion):

 

(initcommandversion)

(command "_.explode" "_all" "")

Kent Cooper, AIA
0 Likes
Message 12 of 14

Anonymous
Not applicable

Well that works then, 

 

Thank you so much everyone for all the help and information!! 

0 Likes
Message 13 of 14

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

Here is a sample of what I have to do. I want to be able to isolate the layer I want to work with ...

If I would be able to add one thing to it, that would be to select a layer to set as current at the beginning so you can turn all other layers off and then a laythw at the end... 


 

Some ideas...

(defun c:STEP1 (/ EN ss)
  (initcommandversion)
  (command "_.-LAYER" "_S" "" PAUSE "_F" "*" "") ; isolate selected layers, freete all others...
  (initcommandversion)
  (command "_.JOIN" "_All" "")
  (if (setq ss (ssget "_X" (list '(0 . "*POLYLINE") (cons 8 (getvar 'clayer)) '(-4 . "&=") '(70 . 1) (cons 410 (getvar 'CTAB))))) ; select all close polylines on current layer
    (command "_.CHPROP" ss "" "_color" "_colorbook" "DIC COLOR GUIDE(R) PART II" "DIC 2630" "")
    (princ "\nNo closed polylines found!"))
  (getkword "\nPress any key to continue...") ; wait...
  (command "_.LAYTHW")
  (princ)
)
0 Likes
Message 14 of 14

nislam04
Participant
Participant

Hi,

Say, I have a dwg file that contains few line under the layer names Like W10X12, W10X15, W10X17.

Can I export them to tekla as a beam whose profiles will be like the layer names Like W10X12, W10X15, W10X17 ?

How to start a lisp for that?

 

Thank you

0 Likes