Rename all xrefs and viewports + change xref path to relative + change textstyle

Rename all xrefs and viewports + change xref path to relative + change textstyle

Sandervp
Advocate Advocate
2,270 Views
5 Replies
Message 1 of 6

Rename all xrefs and viewports + change xref path to relative + change textstyle

Sandervp
Advocate
Advocate

Hello to you all,

 

We need to change a lot of things in our drawings. Most of these are easy by using a lisp with different commands and variables, but I need to add some other functions also....

 

 

Not everybody creates a layer called "xref" for all the external references (for example; me: "xref", you "xrefs"). And sometimes they forget to change the layer into the "xref" layer before they attach an external reference first. 

Some xrefs are locked and some aren't.

 

I need to put all these xrefs into 1 new layer (called "example") and all these xrefs must have a relative path. I can't do this by using the command ( "-xref" "Path" "*").

Also the xref scale must by 1:1.

 

 

Just like the xref layer, are the viewports layers not the same in every drawing. You call him "viewports", he calls it "vports" and I call him "vport".

All the viewports must have the same layer name in each drawing.

 

 

The last requirement concerns all the text and mtext objects. All these objects, also the text from the dimensions, must have a specific .shx textstyle...

 

How can I change all these paths/ layer names/ text objects by using 1 command/ lisp?

 

 

 

Thanks to everybody who wants to help me/ us/

 

 

 

 

 

0 Likes
Accepted solutions (2)
2,271 Views
5 Replies
Replies (5)
Message 2 of 6

hmsilva
Mentor
Mentor
Accepted solution

@Sandervp wrote:

Hello to you all,

 

We need to change a lot of things in our drawings. Most of these are easy by using a lisp with different commands and variables, but I need to add some other functions also....

 

 

Not everybody creates a layer called "xref" for all the external references (for example; me: "xref", you "xrefs"). And sometimes they forget to change the layer into the "xref" layer before they attach an external reference first. 

Some xrefs are locked and some aren't.

 

I need to put all these xrefs into 1 new layer (called "example") and all these xrefs must have a relative path. I can't do this by using the command ( "-xref" "Path" "*").

Also the xref scale must by 1:1.

 

 

Just like the xref layer, are the viewports layers not the same in every drawing. You call him "viewports", he calls it "vports" and I call him "vport".

All the viewports must have the same layer name in each drawing.

 

 

The last requirement concerns all the text and mtext objects. All these objects, also the text from the dimensions, must have a specific .shx textstyle...

 


Hi Sandervp,

 

to change xref's path to Relative, try

 

(defun c:demo (/ files)
  (vl-load-com)
  (setq files "")
  (vlax-For blk (vla-Get-Blocks (vla-Get-ActiveDocument (vlax-Get-Acad-Object)))
    (if	(= (vla-Get-IsXref blk) :vlax-True)
      (setq files (strcat files (vla-get-name blk) ","))
    )
  )
  (if (/= files "")
    (command "-xref" "_T" files "_R")
  )
  (princ)
)

 

to change viewpot and xref layers, try this...

 

I don't have AutoCAD in this laptop, so for the:

'The last requirement concerns all the text and mtext objects. All these objects, also the text from the dimensions, must have a specific .shx textstyle...'

you'll have to do a search in 'Search This Board' for that one... 🙂

 

Hope this helps,
Henrique

EESignature

Message 3 of 6

Sandervp
Advocate
Advocate

Thank you hmsilva!

 

Renaming the xref and change the xref path work by using these lisps.

 

But what do I have to change in the "xref rename lisp" to rename all the viewport layers? 

Like  (if (setq ss (ssget "_X" '((0 . "INSERT")))) into   (if (setq ss (ssget "_X" '((0 . "viewport")))) maybee?

 

Changing lisps is not my professionality....

 

 

0 Likes
Message 4 of 6

hmsilva
Mentor
Mentor

@Sandervp wrote:

Thank you hmsilva!

 

Renaming the xref and change the xref path work by using these lisps.

 

But what do I have to change in the "xref rename lisp" to rename all the viewport layers? 

Like  (if (setq ss (ssget "_X" '((0 . "INSERT")))) into   (if (setq ss (ssget "_X" '((0 . "viewport")))) maybee?

 

Changing lisps is not my professionality....

 

 


Sorry Sandervp,

to select viewports

(if (setq ss (ssget "_X" (list '(0 . "VIEWPORT")(cons -4 "!=") (cons 69 1))))

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 5 of 6

Sandervp
Advocate
Advocate

Hello Hmsilva,

 

If I use the lisp for renaming the xref's, it works but if I change the lisp file into;

 

(defun c:VPRENAME ( / ent i lay laylst ss)

(defun VP_layer (name / l layx)
  (if (and (setq l (tblobjname "layer" name))
	   (setq layx (entget l))
	   )
    (if (/= 4 (logand 4 (cdr (assoc 70 layx))))
      (setq laylst (cons (cons layx 4) laylst))
      )
    (entmake (list (cons 0 "LAYER")
		   (cons 100 "AcDbSymbolTableRecord")
		   (cons 100 "AcDbLayerTableRecord")
		   (cons 2 name)
		   (cons 70 4)
		   )
	     )
    )
  )

  (if (setq ss (ssget "_X" (list '(0 . "VIEWPORT")(cons -4 "!=") (cons 69 1))))
    (progn
      (VP_layer "VIEWPORT");; change layer name
      (VP_layer "VIEWPORT");; change layer name
      (repeat (setq i (sslength ss))
	(setq ent (entget (ssname ss (setq i (1- i)))))
	(if
	  (= 4
	     (logand 4
		     (cdr (assoc 70 (tblsearch "BLOCK" (cdr (assoc 2 ent)))))
	     )
	  )
	   (progn
	     (setq lay (entget (tblobjname "layer" (cdr (assoc 8 ent)))))
	     (if (= 4 (logand 4 (cdr (assoc 70 lay))))
	       (progn
		 (setq laylst (cons (cons lay (cdr (assoc 70 lay))) laylst))
		 (entmod (subst (cons 70 0) (assoc 70 lay) lay))
	       )
	     )
	     (if (= (cdr (assoc 410 ent)) "Model")
	       (entmod (subst (cons 8 "VIEWPORT") (assoc 8 ent) ent));; change layer name
	       (entmod (subst (cons 8 "VIEWPORT") (assoc 8 ent) ent));; change layer name
	       )
	   )
	)
      )
      (if laylst
	(foreach lay laylst
	  (entmod (subst (cons 70 (cdr lay)) (assoc 70 (car lay)) (car lay)))
	)
      )
    )
  )
  (princ)
)

the message; "bad argument type: stringp nil" appears in the commandline

 

0 Likes
Message 6 of 6

hmsilva
Mentor
Mentor
Accepted solution

Hi Sandervp,

to change all viewports layer to layer VIEWPORT, try:

 

(vl-load-com)
(defun c:demo (/ layers locklst)
    (or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
    (setq layers (vla-Get-Layers adoc))
    (vlax-for lay layers
        (if (= (vla-get-lock lay) :vlax-true)
            (progn
                (setq locklst (cons (vla-get-name lay) locklst))
                (vla-put-lock lay :vlax-false)
            )
        )
    )
    (vla-add layers "VIEWPORT")
    (vlax-for layt (vla-get-layouts adoc)
        (if (eq :vlax-false (vla-get-modeltype layt))
            (vlax-for obj (vla-get-block layt)
                (if (= (vla-get-objectname obj) "AcDbViewport")
                    (vla-put-layer obj "VIEWPORT")
                )
            )
        )
    )
    (if locklst
        (vlax-for lay layers
            (if (vl-position (vla-get-name lay) locklst)
                (vla-put-lock lay :vlax-true)
            )
        )
    )
    (princ)
)

 

Hope this helps,
Henrique

EESignature

0 Likes