MatchProp for Layers

MatchProp for Layers

istvan_voiculescu
Enthusiast Enthusiast
2,780 Views
9 Replies
Message 1 of 10

MatchProp for Layers

istvan_voiculescu
Enthusiast
Enthusiast

I think this would be a simple routine. I have two layers. Layer 1 with its properties and Layer2 with its properties. I want to push the Layer 1 Properties to Layer 2, in the same way as we would do a matchprop for objects, so in the end the Layer2 has identical properties to Layer1. 

I know I could create a Layer 3 from Layer1 and then merge Layer2 in Layer 3 and rename Layer3 to Layer 2. But that would take a lot....

Or I could select both in Layer Manager and then one by one match each property...

 

So it would act in a way like LayerMerge... Select the source layer from a list, then copy its properties, select the target layer(s) from a list and paste the source layer properties to the target layers to be identical.

ISTVAN “ISHKA” VOICULESCU
CAD/IT Systems Admin Sr.
BIM / CADD MANAGER
CITY OF AUSTIN, PUBLIC WORKS DEPARTMENT
ENGINEERING SERVICES DIVISION
0 Likes
Accepted solutions (1)
2,781 Views
9 Replies
Replies (9)
Message 2 of 10

pbejse
Mentor
Mentor

@istvan_voiculescu wrote:

I think this would be a simple routine. I have two layers. Layer 1 with its properties and Layer2 with its properties...


 

Try this , the option of  selecting objects as source and target for the layer names. 

If that doesnt work for you then we will add the listbox as requested.

 

 

0 Likes
Message 3 of 10

istvan_voiculescu
Enthusiast
Enthusiast

It does what I want and this is great, but requires both layers to be selected by objects. I could dive in modifying the code and it might take me a while, but can this code be slightly modified to do the following:
1. Select the target layer by selecting one object in the drawing.
2. Display target layer in a dialog box. or list it in the command line.(So we know what layer is selected)
3. Provide a command line where we can type a layer or list box of the layers in the CAD file to select from for the source data to be matched.
4. Apply the change.

The idea behind this type of routine is the following. We have CAD files that need to be kept with original layers, but those layers need to be modified to match our standards. To match our standards and still keep the original standards for printing we need to change their properties to match our standards. Then at the end the CAD file would have two layer states. The original as the file was provided and the modified for our purposes... We could do those one by one manually, or import our layers temporary and match the layers to our layers properties for the same type of data.
Thanks a lot.

ISTVAN “ISHKA” VOICULESCU
CAD/IT Systems Admin Sr.
BIM / CADD MANAGER
CITY OF AUSTIN, PUBLIC WORKS DEPARTMENT
ENGINEERING SERVICES DIVISION
0 Likes
Message 4 of 10

istvan_voiculescu
Enthusiast
Enthusiast

(defun c:match-layer-prop1 (/ source target)
(and
(setq target (car (entsel "\nSelect an object on target layer: ")))
(setq target
(entget (tblobjname "layer" (cdr (assoc 8 (entget target))))
)
)
(princ
(strcat
"\nSelected Layer is: "
(cdr (assoc 2 target))
)
)
(setq source (getstring 1 "\nWhat layer should be matched to: "))
(setq source
(entget (tblobjname "layer" (cdr (assoc 8 (entget source))))
)
)
(entmod
(append (vl-remove-if
'(lambda (x) (member (car x) '(70 62 6 290 370 390 347)))
target
)
(vl-remove-if-not
'(lambda (x) (member (car x) '(70 62 6 290 370 390 347)))
source
)
)
)
(entupd (cdr (assoc -1 target)))
)
(princ)
)

 

It fails at the selecting the source section where I get an lentityp error... What am I missing?

Also, I cannot use the alert command, just the princ, since it seems when using alert it just skips...

ISTVAN “ISHKA” VOICULESCU
CAD/IT Systems Admin Sr.
BIM / CADD MANAGER
CITY OF AUSTIN, PUBLIC WORKS DEPARTMENT
ENGINEERING SERVICES DIVISION
0 Likes
Message 5 of 10

pbejse
Mentor
Mentor
Accepted solution

@istvan_voiculescu wrote:

1. Select the target layer by selecting one object in the drawing.
2. Display target layer in a dialog box. or list it in the command line.(So we know what layer is selected)
3. Provide a command line where we can type a layer or list box of the layers in the CAD file to select from for the source data to be matched.
4. Apply the change.


 

;; List Box  -  Lee Mac
;; Displays a DCL list box allowing the user to make a selection from the supplied data.
;; msg - [str] Dialog label
;; lst - [lst] List of strings to display
;; bit - [int] 1=allow multiple; 2=return indexes
;; Returns: [lst] List of selected items/indexes, else nil

(defun LM:listbox ( msg lst bit / dch des tmp rtn )
    (cond
        (   (not
                (and
                    (setq tmp (vl-filename-mktemp nil nil ".dcl"))
                    (setq des (open tmp "w"))
                    (write-line
                        (strcat "listbox:dialog{label=\"" msg "\";spacer;:list_box{key=\"list\";multiple_select="
                            (if (= 1 (logand 1 bit)) "true" "false") ";width=50;height=15;}spacer;ok_cancel;}"
                        )
                        des
                    )
                    (not (close des))
                    (< 0 (setq dch (load_dialog tmp)))
                    (new_dialog "listbox" dch)
                )
            )
            (prompt "\nError Loading List Box Dialog.")
        )
        (   t     
            (start_list "list")
            (foreach itm lst (add_list itm))
            (end_list)
            (setq rtn (set_tile "list" "0"))
            (action_tile "list" "(setq rtn $value)")
            (setq rtn
                (if (= 1 (start_dialog))
                    (if (= 2 (logand 2 bit))
                        (read (strcat "(" rtn ")"))
                        (mapcar '(lambda ( x ) (nth x lst)) (read (strcat "(" rtn ")")))
                    )
                )
            )
        )
    )
    (if (< 0 dch)
        (unload_dialog dch)
    )
    (if (and tmp (setq tmp (findfile tmp)))
        (vl-file-delete tmp)
    )
    rtn
)


(defun c:match-layer-prop (/ source target)
;;	_gile | pbe   2021	;;
  (defun _Layerlist (cs / a ln ls)
    (while (setq a (tblnext "Layer" (null a)))
	(cond
	  ((or (vl-string-search "$0$" (setq ln (cdr (assoc 2 a))))
	       (member ln (list "0" "Defpoints" cs))))
	  ((setq ls (cons ln ls)))))
    ls
    )
  (if
    (and
    	(setq target (car (entsel "\nSelect an object on target layer: ")))
	(setq target (entget (tblobjname "layer"
			       (setq lnm (cdr (assoc 8 (entget target)))))))
	(setq layList (_Layerlist lnm))
	(setq source (car (LM:listbox (strcat "Select layer to matched with " lnm ) layList 0)))
	(setq source
		   (entget (tblobjname "layer" source)
		   )
	    )
	)
	(progn
	    (entmod
	      (append (vl-remove-if
			'(lambda (x) (member (car x) '(70 62 6 290 370 390 347)))
			target
		      )
		      (vl-remove-if-not
			'(lambda (x) (member (car x) '(70 62 6 290 370 390 347)))
			source
		      )
	      )
	    )
	    (entupd (cdr (assoc -1 target)))
	  )
    )
  (princ)
)

 

 

Command: MATCH-LAYER-PROP 

Select an object on target layer:

 

pbejse_0-1623469206711.png

 


@istvan_voiculescu wrote:

It fails at the selecting the source section where I get an lentityp error... What am I missing?,,


This will fail

 

...
(setq source (getstring 1 "\nWhat layer should be matched to: "))
    (setq source
	   (entget (tblobjname "layer" (cdr (assoc 8 (entget source))))
	   )
    )
...

 

As source is a string as a result from getstring and entget requires an ename to work

 

...    
(setq source (getstring 1 "\nWhat layer should be matched to: "))
    (setq source
	   (entget (tblobjname "layer" source)
	   )
    )

 

 

HTH

0 Likes
Message 6 of 10

ronjonp
Advisor
Advisor

You could try this too:

 

(defun foo (l1 l2 / a b)
  (if (and (setq a (tblobjname "layer" l1)) (setq b (tblobjname "layer" l2)))
    (entmod
      (append
	(entget b)
	(vl-remove-if-not '(lambda (x) (vl-position (car x) '(6 62 70 290 347 370 390 420 430))) (entget a))
      )
    )
  )
)
(foo "0" "1")

 

0 Likes
Message 7 of 10

istvan_voiculescu
Enthusiast
Enthusiast

Thanks a lot. That is what I was looking for. I could have used also the solution without the listbox, since I don't mind typing, but this makes it so much easier... I am not an expert at LISP, but can move code around and apply some logic to it 🙂 Most of the time I get lost in parentheses 🙂

Hopefully others find this helpful especially for matching layer data to standards while keeping original layer names...

The idea is that we have the file we need to keep from the consultant as is, but modify its layer properties for our plans. So once those layers are defined in the CAD file, then if the consultant sends a new version, we just remove the original content from the CAD file and paste the data from the new file in. Easy swap while maintaining all the work done at the beginning 🙂 And Layer States take care of everything 🙂

ISTVAN “ISHKA” VOICULESCU
CAD/IT Systems Admin Sr.
BIM / CADD MANAGER
CITY OF AUSTIN, PUBLIC WORKS DEPARTMENT
ENGINEERING SERVICES DIVISION
0 Likes
Message 8 of 10

pbejse
Mentor
Mentor

@istvan_voiculescu wrote:

Thanks a lot. That is what I was looking for.


 

Good to know it works for you.  You may want to look into _laytrans  to deal with layer standards

 

Cheers

 

 

0 Likes
Message 9 of 10

istvan_voiculescu
Enthusiast
Enthusiast

Can the routine be updated to sort the layers in the listbox alphabetically? It seems that the layers are listed in the order they are created in the CAD file... Otherwise it works great...

ISTVAN “ISHKA” VOICULESCU
CAD/IT Systems Admin Sr.
BIM / CADD MANAGER
CITY OF AUSTIN, PUBLIC WORKS DEPARTMENT
ENGINEERING SERVICES DIVISION
0 Likes
Message 10 of 10

pbejse
Mentor
Mentor

@istvan_voiculescu wrote:

Can the routine be updated to sort the layers in the listbox alphabetically? It seems that the layers are listed in the order they are created in the CAD file... Otherwise it works great...


Yuuppppppp.

Add the line in blue color

...
(setq layList (_Layerlist lnm)) (setq layList (vl-sort layList '<)) (setq source (car (LM:listbox (strcat "Select layer to matched with " lnm ) layList 0)))
...

HTH

 

0 Likes