cadman6735 发表于 2022-7-6 10:51:29

nentsel, entget, ssget questio

I am working on a macro that will put all my entities in a drawing color to bylayer.Here is my code so far and it works but I have to select each entity one at a time.
 

(defun C:CBL ( / oldData newData);=========================================== (While (setq oldData (entget(car(nentsel)))) (setq newData (subst (cons 62 256)(assoc 62 oldData)oldData)) (entmod newData) (command "REGEN"));end while;========================================== (princ))
 
 
 
Question #1
 
How would I use ssget to accomplish this task?(ssget "x")
I am having trouble understanding how to use ssget.
 
 
Question #2
 
(subst (cons 62 256)(assoc 62 oldData)oldData) from my above code.
 
I don't 100% understand how this works.Why do I use oldData at the end of this function?Why do I have to call oldData twice?Can someone explain what each oldData is doing?
 
 
Question #3
 
My ultimate goal is to be able to put all entities in a drawing plotstyle to bylayer.This seems to be a much bigger task from what I am reading.
 
Is there not a DXF code for plot syle?How do I access the plotsyles to modify it.Seems it is a vl functions but I am not at that level of understanding LISP yet, so how was it accomplished before Visual Lisp done in "vanilla LISP"?
 
 
Thanks

Tharwat 发表于 2022-7-6 10:56:50

You can select all the objects in your drawing and stright to the pop-up-list of Layer Colors and select it ByLayer and that will solve the issue.
 
Regards
Tharwat

JohnM 发表于 2022-7-6 11:01:30

this might be a shortcut
(command "change" "all" "" "properties" "color" "bylayer" "")
draw backs are:
if you are in model space it will only change those objects
if you are in paper space it will only chanf that tab
 
if you want to change all objexts in model and paper you need to use ssget "x" then use a while loop with ssname

Tharwat 发表于 2022-7-6 11:01:47

This will select all entities in your drawing
 

(setq objs (ssget "_x"))
 
 
Regards.
 
Tharwat

alanjt 发表于 2022-7-6 11:05:22

2008 had the SetByLayer command.

cadman6735 发表于 2022-7-6 11:09:45

 
 
 
Thanks Alan
 
 
This command does everything I want my macro to do. I wish I knew about this command before now, This is great. Thanks
 
 
 
But
 
I am still on the quest to understand how to do it via lisp...
 
 
 
Can you take a crack at question #2 for me? I would like to understand how the "assoc" function works and why I have to call out oldData twice.
 
 
Thanks

alanjt 发表于 2022-7-6 11:12:44

I posted this a while back about using SetByLayer:

alanjt 发表于 2022-7-6 11:16:00

Answer to question #2:
 
Subst has three parameters that must be filled.

(subst   ) = the item you want to replace the old with.
   = the old item you want to replace with new (you don't know it, so you must call it from the list)
   = the list you want to edit.
 
eg.

Command: (setq lst (list (cons 1 "ALAN") (cons 2 "THOMPSON")))((1 . "ALAN") (2 . "THOMPSON"))Command: (assoc 1 lst)(1 . "ALAN")Command: (subst (cons 2 "NAME") (assoc 2 lst) lst)((1 . "ALAN") (2 . "NAME"))If I want to replace item A with B, I have to call it from the list first.
 
You're only calling the list once. The second parameter of subst is you extracting the item to replace from the list.

cadman6735 发表于 2022-7-6 11:18:39

 
 
 
 
Thanks again Alan
 
 
It sounds so straight forward the way you put it, I could not find a good example to explain it to me in a way that I could get my head around it.
 
 
 
Not to be greedy here but...
 
From my understanding so far...If I want to get information about an element I have to use (entsel) & (entget) together.Where (entsel) allows me to select the element and (entget) pull the information from the element. (DxF codes)
 
But (ssget) seems to work differently.
(ssget) seems to work as a selection/filter tool.Where I have to provide (ssget) a dot list to work from.So if I used (ssget "x") this would put all my drawing elements into a selection set.But it seems I have to specify what I want to work with from the selection set, example: (0 . "Line") or (8 . 256)
 
I can't use this selection set on multiple object such as "line" & "circles", I have to choose one or the other.
 
 
Am I on the right track or is there more to ssget?
 
Thanks again

alanjt 发表于 2022-7-6 11:24:23

Use of subst outside of editing an entity list:
eg.

Command: (setq lst (list "I'M" "SINGLE"))("I'M" "SINGLE")Command: (subst "MARRIED" "SINGLE" lst)("I'M" "MARRIED")
 
 
This will also come in handy: AutoLISP Reference
页: [1] 2
查看完整版本: nentsel, entget, ssget questio