I have lost my knowledge

I have lost my knowledge

HullDrafter
Advocate Advocate
855 Views
2 Replies
Message 1 of 3

I have lost my knowledge

HullDrafter
Advocate
Advocate

I was learning AutoLISP and have since been away from it for about 6 years. As such, I have forgotten.

 

I need help with someone else's program. If I could remember where I found it, I would ask them.

 

The Program;

 

(defun c:XR253 (/ xr1 xr2 xr3 xr4 xr5 xr6 tx1 tb1)
(if (setq
xr1 (entsel "\nSelect Xref to change all layers to color 253: ") ;; <--- Change color number as needed
) ;_ end of setq
(progn
(setq xr2 (entget (car xr1)))
(setq tx1 (cdr (assoc 0 xr2)))
(if (and (= tx1 "INSERT")
) ;_ end of and
(progn
(setq xr3 (cdr (assoc 2 xr2)))
(setq xr4 (tblsearch "block" xr3))
(if (setq xr5 (cdr (assoc 1 xr4)))
(progn
(setq xr6 (strcat xr3 "|*"))
(command "-layer" "c" "253" xr6 "") ;;; <---Change color number as needed
) ;_ end of progn
(prompt (strcat "\n" xr3 " is not an X-Ref."))
) ;_ end of if
) ;_ end of progn
(prompt "\nNo valid XREF selected")
) ;_ end of if
) ;_ end of progn
(princ " ...Nothing selected")
) ;_ end of if
(princ)
)

 

Could someone spell out what each line is suppose to do. I am currently looking up commands so that I might change this one in the future.

 

Currently, it "should" allow the user to select an "XREF" and it will change every layer to color 253. I need to be able to change it, to change specific layers to 253 but to also change the linetype to "Hidden2". 

 

Later, I will expand the program to change a complete set of layers and linetypes to the various colors and linetypes that I need.

 

I know what "setq" does. But, when I see commands such as (setq xr2 (entget (car xr1), (setq tx1 (cdr (assoc 0 xr2) or (setq xr3 (cdr (assoc 2 xr2),

I really don't have a clue what I am facing. 

So, I am asking for some help. Please help me to understand what this program is doing.

Thank you,

HD

0 Likes
Accepted solutions (2)
856 Views
2 Replies
Replies (2)
Message 2 of 3

dlanorh
Advisor
Advisor
Accepted solution
(defun c:XR253 (/ xr1 xr2 xr3 xr4 xr5 xr6 tx1 tb1)
;asks for an entity selection and stores the entity name in variable xr1
;It also tests if anything was selected
(if (setq xr1 (entsel "\nSelect Xref to change all layers to color 253 : "));entsel returns a list entity name and point picked If something was selected (progn ;If something was selected (setq xr2 (entget (car xr1))) ;gets the entity data (setq tx1 (cdr (assoc 0 xr2))) ;gets the data value of entity "type" (dxf code 0 of entity data) (if (= tx1 "INSERT") ;Is the data type "INSERT" (a block) (progn ;If yes
(setq xr3 (cdr (assoc 2 xr2))) ;get block name from entity data (setq xr4 (tblsearch "block" xr3)) ;searches block table for block name and gets data (if (setq xr5 (cdr (assoc 1 xr4))) ;This is looking to get the <xref path>?? (progn (setq xr6 (strcat xr3 "|*")) ;Adds |* to the end of the block name string (command "-layer" "c" "253" xr6 "") ;Change colour of all block 253 layers to colour 253
) ;_ end of progn (prompt (strcat "\n" xr3 " is not an X-Ref."));Displays a messageon a new line ) ;_ end of if ) ;_ end of progn (prompt "\nNo valid XREF selected") ) ;_ end of if ) ;_ end of progn (princ " ...Nothing selected") ) ;_ end of if (princ) );end_defun

I'm not sure if this works. Variable xr5 is set but never used or tested at a crucial point

I am not one of the robots you're looking for

0 Likes
Message 3 of 3

Kent1Cooper
Consultant
Consultant
Accepted solution

@dlanorh wrote:
….
          (if (setq xr5 (cdr (assoc 1 xr4))) ;This is looking to get the <xref path>??
            (progn
              (setq xr6 (strcat xr3 "|*")) ;Adds |* to the end of the block name string
              (command "-layer" "c" "253" xr6 "") ;Change colour of all block 253 layers to colour 253
….

.... Variable xr5 is set but never used or tested at a crucial point


 

Yes, that first line is getting the path, but it doesn't need to go that far, either to pull out the path or to put it in a variable.  Its effect is to determine whether the selected object is an Xref.  There are other ways, but this is pretty simple, because ordinary Blocks, though they are also "INSERT" objects, don't have a path.  But all it really needs to do is to check whether there is  an (assoc 1) entry in the entity data of the entry in the Block table:

….
(if (assoc 1 xr4); there is a path [don't care what it is], therefore it's an Xref
(progn
(setq xr6 (strcat xr3 "|*")); string of Xref name, "pipe", and everything wildcard
; the | is the separator between Xref name and Xref-dependent Layer name(s)

(command "_.layer" "_c" "253" xr6 ""); Change all Xref-dependent layers to color 253 ….

and that same line can also give the linetype, if you wanted to give it to all  Layers in the Xref:

        (command "_.layer" "_c" "253" xr6 "_ltype" "hidden2" xr6 "")

If you can describe which specific Layers you need changed instead of all of them, it may be easy to adjust.  For example, if you want to it to happen to all Layers in the Xref that begin with "Begin", you can just make that part of the wildcard string of Xref-dependent Layer names earlier:

        (setq xr6 (strcat xr3 "|Begin*"))

and use the same Layer-command line to give just those Layers that color and linetype.

Kent Cooper, AIA