Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using AutoCAD command to change Vport layer

42 REPLIES 42
SOLVED
Reply
Message 1 of 43
mruPRQUJ
2696 Views, 42 Replies

Using AutoCAD command to change Vport layer

Hi there,
I am wondering if it is possible to use AutoCAD command to finish below task, (to input AutoCAD command in command line, in order to create script later)
change all Vport to layer $X-ANNO-VPRT,
color by layer,

Bring Vport to Front (in draw order)

 

 

Thank you very much in advance! 🙂

Labels (1)
42 REPLIES 42
Message 2 of 43
paullimapa
in reply to: mruPRQUJ

code already written in this thread

Just change the layerName:

 (vla-add (vla-get-layers acDoc) (setq layerName "0-VPRT"))

To your LayerName:

 (vla-add (vla-get-layers acDoc) (setq layerName "$X-ANNO-VPRT"))

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 43
mruPRQUJ
in reply to: paullimapa

sorry, is it possible to use AutoCAD command to do it? They can be used in script later, many thanks.

Message 4 of 43
paullimapa
in reply to: mruPRQUJ

Unfortunately, other than LISP I don't know of a command line version that can select All Vports in All Layouts to change all of them to another Layer. Also the built-in AutoCAD commands QSELECT and FILTER require dialog user entry to select the object type.

Do you still have old LT versions that are not 2024 which don't support lisp  but only script files?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 43
mruPRQUJ
in reply to: paullimapa

Most case. there is only one Vport, one layout in the drawing. We can consider only change one Vport, one layout, thanks.

Message 6 of 43
paullimapa
in reply to: mruPRQUJ

I still don't know of an AutoCAD command line that can select and filter out a VPort object from all other objects in a layout.

One trick if you know the layer name that the VPort is currently on then the SelectSimilar command can be used. Assuming current VPort is on layer name "SET-VP" and layer  name "$X-ANNO-VPRT" does not exist in the dwg then the following Script will work:

_.Tilemode
0
_.Pspace
.-Layer
_M
$X-ANNO-VPRT
_Set
SET-VP

_.Mview
0,0
1,1
_.SelectSimilar
_L

_.Chprop
_LA
$X-ANNO-VPRT
_CO
_BYLAYER

_.Erase
_L

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 7 of 43
paullimapa
in reply to: mruPRQUJ

Update.  Found the SELECTSIMILARMODE system variable that can be changed on the command line to impact SELECTSIMILAR command settings.

So you can now run this Script file without knowing what the current Vport layer name is:

 

SELECTSIMILARMODE
128
_.Tilemode
0
_.Pspace
.-Layer
_M
$X-ANNO-VPRT

_.Mview
0,0
1,1
_.SelectSimilar
_L

_.Chprop
_LA
$X-ANNO-VPRT
_CO
_BYLAYER

_.Erase
_L

 

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 8 of 43
mruPRQUJ
in reply to: paullimapa

The current Vport layer name could vary.

Message 9 of 43
mruPRQUJ
in reply to: paullimapa

could you please add Bring Vport to Front in draw order? thanks.

Message 10 of 43
paullimapa
in reply to: mruPRQUJ

O you should know how to add that but here's yet another improved version without messing with SelectSimilar settings but instead rely only on AutoCAD's built-in MView command:

 

_.Tilemode
0
_.Pspace
.-Layer
_M
$X-ANNO-VPRT

_.Mview
_On
_All

_.Chprop
_P

_LA
$X-ANNO-VPRT
_CO
_BYLAYER

_.DRAWORDER
_P

_Front

 

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 11 of 43
mruPRQUJ
in reply to: paullimapa

Great job! Sorry to bother you, can I ask you one more question? If I want to add this script to Macro, how to modify it? many thanks.

Message 12 of 43
paullimapa
in reply to: mruPRQUJ

Try this:

^C^C_.Tilemode;0;_.Pspace;.-Layer;_M;$X-ANNO-VPRT;;_.Mview;_On;_All;;_.Chprop;_P;;_LA;$X-ANNO-VPRT;_CO;_BYLAYER;;_.DRAWORDER;_P;;_Front;

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 13 of 43
mruPRQUJ
in reply to: paullimapa

Original is below and it works, 

^C^C-LAYER;LOCK;$X-ANNO-VPRT;LOCK;$X-ANNO-VPRT;;MVIEW;L;ON;ALL;;

 

 

new one is below, it did not work.

^C^C-LAYER;LOCK;$X-ANNO-VPRT;LOCK;$X-ANNO-VPRT;;MVIEW;L;ON;ALL;;_.Tilemode;0;_.Pspace;.-Layer;_M;$X-ANNO-VPRT;;_.Mview;_On;_All;;_.Chprop;_P;;_LA;$X-ANNO-VPRT;_CO;_BYLAYER;;_.DRAWORDER;_P;;_Front;;

thanks a lot!

Message 14 of 43
paullimapa
in reply to: mruPRQUJ

It's possible that what I provided would fail if the current Vport's Layer is Locked.

Since you don't know what layer the current Vport is on, this means the new macro would have to include the Layer command to Unlock All Layers. Then at the end add back Layer Lock $X-ANNO-VPRT which is what the following macro should do:

 

^C^C_.Tilemode;0;_.Pspace;.-Layer;_Unl;*;;_.Mview;_L;_ON;_ALL;;_.Chprop;_P;;_LA;$X-ANNO-VPRT;_CO;_BYLAYER;;_.DRAWORDER;_P;;_Front;.-Layer;_Lo;$X-ANNO-VPRT;;

 

So you don't need to include your original macro. The above should take care of locking both the layer & the vport

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 15 of 43
mruPRQUJ
in reply to: paullimapa

 Hi there, the original Macro can only lock the Vport display. Sorry about it, it has some problems. In Macro "$" character is used for different function, so its causing a problem. 

Someone created a lisp for it, it is not perfect, it works, many thanks.

 

Message 16 of 43
paullimapa
in reply to: mruPRQUJ

Of course you can run LL automatically after loading. But I also changed the sequence of the lines in your code to make it work. Again since your code does NOT include an option to UnLock ALL Layers the changing of the Vport Layer ONLY works if the Layer the Vport is on is NOT locked:

(defun c:LL()
; Layer Make sets Layer current
(Command "_.-LAYER" "_MAKE" "$X-ANNO-VPRT" "")
; Layer New creates Layer but does not set as current so you decide which one you want to use
;(Command "_.-LAYER" "_NEW" "$X-ANNO-VPRT" "")
; You can continue the Layer Lock as part of above code or start new command like this
; Layer Locks the Vport layer
(Command "_.-LAYER" "_LOCK" "$X-ANNO-VPRT" "")
; Now before running Mview command you need to first set Tilemode to 0
(COMMAND "_.TILEMODE" "0")
; then make sure is in Paper space & not in Model space inside a Vport
(Command "_.PSPACE")
; now run Mview command to Lock & turn On all Vports in current Layout
(Command "_.MVIEW" "_LOCK" "_ON" "_ALL" "")
; Chprop command Previous will only succeed if the current Vport's Layer is NOT Locked and there are Vports found in the current Layout
(Command "_.CHPROP" "_P" "" "_LAYER" "$X-ANNO-VPRT" "_COLOR" "BYLAYER" "")
; Draworder command only works if there are Previous Vports found
(Command "_.DRAWORDER" "_P" "" "_FRONT")
(princ)
)
; automatically run the command
(c:LL)

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 17 of 43
mruPRQUJ
in reply to: mruPRQUJ

Great! It works perfect! Another lisp has minor changes, I lost the original link. Can I post here or make a new post? Finally, I want to combine two lisps together, many thanks.

Message 18 of 43
paullimapa
in reply to: mruPRQUJ

Best to start a new post on that lisp


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 19 of 43
mruPRQUJ
in reply to: paullimapa

Thanks a million!  🙂

Message 20 of 43
paullimapa
in reply to: mruPRQUJ

Glad to have helped…cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report