Author Topic: Move object to layers  (Read 9297 times)

0 Members and 1 Guest are viewing this topic.

CADwoman

  • Guest
Move object to layers
« on: February 10, 2005, 11:36:00 AM »
Hello,

I'm new to this forum. I need help on writing a startup lisp routine to move all viewport objects to the defpoint layer. THis is what I have so far:

MOVE VIEWPORT OBJECTS TO DEFPOINT
(setq ss1 (ssget "X" '((0 . "VIEWPORT"))))
(command "chprop" "p" """layer""defpoints""")

It works, but the only problem is when you open a file that does not have a viewport, the autocad returns an error:

Invalid option keyword.

! Function cancelled

What can I use to detect if the file is in paperspace?

Thanks

SMadsen

  • Guest
Move object to layers
« Reply #1 on: February 10, 2005, 11:42:59 AM »
You could check TILEMODE:

Code: [Select]
(cond ((= (getvar "TILEMODE") 0)
       (setq ss1 (ssget "X" '((0 . "VIEWPORT"))))
       (command "chprop" ss1 "" "layer" "defpoints" ""))
)


or you could simply issue the command only if SSGET created a selection:

Code: [Select]
(if (setq ss1 (ssget "X" '((0 . "VIEWPORT"))))
  (command "chprop" ss1 "" "layer" "defpoints" "")
)


Welcome to theSwamp, by the way.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Move object to layers
« Reply #2 on: February 10, 2005, 11:45:32 AM »
Maybe I misunderstood the question.   :roll:
But what about something like this?
Code: [Select]

(if (> (length (setq ss1 (ssget "X" '((0 . "VIEWPORT")))))  0)
    (command "chprop" "p" """layer""defpoints"""))
    )




*stig wins again*
:D
TheSwamp.org  (serving the CAD community since 2003)

CADwoman

  • Guest
Move object to layers
« Reply #3 on: February 10, 2005, 12:04:32 PM »
Thank you so much! this is great!

Quote from: SMadsen
You could check TILEMODE:

Code: [Select]
(cond ((= (getvar "TILEMODE") 0)
       (setq ss1 (ssget "X" '((0 . "VIEWPORT"))))
       (command "chprop" ss1 "" "layer" "defpoints" ""))
)


or you could simply issue the command only if SSGET created a selection:

Code: [Select]
(if (setq ss1 (ssget "X" '((0 . "VIEWPORT"))))
  (command "chprop" ss1 "" "layer" "defpoints" "")
)


Welcome to theSwamp, by the way.

CADwoman

  • Guest
Move object to layers
« Reply #4 on: February 22, 2005, 10:42:50 AM »
Thanks, when I ran it, AUtocad returned:

! bad argument type: listp <Selection set: 9>

Quote from: Mark Thomas
Maybe I misunderstood the question.   :roll:
But what about something like this?
Code: [Select]

(if (> (length (setq ss1 (ssget "X" '((0 . "VIEWPORT")))))  0)
    (command "chprop" "p" """layer""defpoints"""))
    )




*stig wins again*
:D

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Move object to layers
« Reply #5 on: February 22, 2005, 11:29:08 AM »
Mark meant to use sslength but inadvertently used length. Change that and it will work.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Move object to layers
« Reply #6 on: February 22, 2005, 11:44:37 AM »
You may want to include error trap for empty ss1, like this:
Code: [Select]
(if (and (setq ss1 (ssget "X" '((0 . "VIEWPORT"))))
         (> (sslength ss1)  0))
   (command "chprop" "p" """layer""defpoints""")
)


Edit
Now that i look at it ss1 will never be zero length, right?
so just test for nil.
Code: [Select]
(if (setq ss1 (ssget "X" '((0 . "VIEWPORT"))))
   (command "chprop" "p" """layer""defpoints""")
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Move object to layers
« Reply #7 on: February 22, 2005, 02:20:36 PM »
And on further review, this won't always work either. (ssget "x" '((0 . "VIEWPORT"))) will ALWAYS return a selection set, even if you have no VP's defined. Each layout tab has a VP associated with it that you cannot do anything with (without generating errors anyway). Also, since the command is using "p" for the selection set, there is no reason to use (setq ss1.....

Command: chprop

Select objects: p
1 found
1 was the paper space viewport.

Select objects:
Command:

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Move object to layers
« Reply #8 on: February 22, 2005, 02:26:14 PM »
Shoot, hit the submit button by mistake....
Here's code that will work providing that the defpoints layer exists.
Code: [Select]

(if (> (sslength (ssget "X" '((0 . "VIEWPORT")))) 1)
   (command "chprop" "p" """layer""defpoints""")
)

CADwoman

  • Guest
Move object to layers
« Reply #9 on: February 22, 2005, 03:06:32 PM »
Thank you all for your help. Now I have a startup script that checks for Tilemode 0, then move all viewport objects to defpoint and then lock the VP display. This is very useful to me because I'm dealing with a large group of users who don't always remember to put Vports in the right layers.

Thanks again!


;DESCRIPTION:;MOVE VIEWPORT OBJECTS TO DEFPOINTS and DISPLAY LOCK
(cond ((= (getvar "TILEMODE") 0)
       if(setq ss1 (ssget "X" '((0 . "VIEWPORT"))))
       (command "chprop" ss1 "" "layer" "defpoints" "")
   (command "-vports" "lock" "on" ss1""))
)

ronjonp

  • Needs a day job
  • Posts: 7527
Move object to layers
« Reply #10 on: February 22, 2005, 03:24:59 PM »
CadWoman,

I don't know how many people you work with, but if you could get this vba routine into their startup suite.....you wouldn't have to worry about the viewports being on the wrong layer.

http://theswamp.org/lilly_pond/ronjonp/create_lyrs.zip?nossi=1

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Move object to layers
« Reply #11 on: February 22, 2005, 03:32:28 PM »
CADwoman,
If you use more than 1 layout then your routine will only work with the active one. In order to modify the viewports in ANY layout, regardless of TILEMODE value, you could use ActiveX to accomplish the task. If you'd like to see that solution, just say so......

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Move object to layers
« Reply #12 on: February 22, 2005, 03:34:15 PM »
Jeff,
Thanks for the info.
If the selection set is always 1 or greater, you don't need the test, just
Code: [Select]
(ssget "X" '((0 . "VIEWPORT")))
(command "chprop" "p" """layer""defpoints""")


BUT, I did some testing and got this error
Code: [Select]

chprop
Select objects: p 1 found
1 was not in current space.

Select objects:
Command: layer
Current layer:  "0"
Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/Plot/PStyle/Freeze/Thaw/LOck/Unlock]:
 0
Invalid option keyword.


I tried several combinations & what I found was this.
If you are in model space the chprop command generates an error
If you are in a tab with no vp it generates an error
If you have DWG with 2 tabs and no VP will generate an error
If you have a DWG with 2 tabs & one vp not in the current tab it generates an error
If you have a DWG with 2 tabs & one vp in the current tab & active it generates an error

Conclusion:
chprop only works on items in the current space.
(ssget "X" '((0 . "VIEWPORT"))) gets all tabs as well as view ports so the tabs must be filtered

Looks like more code is needed. 8)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Move object to layers
« Reply #13 on: February 22, 2005, 03:36:35 PM »
Ugh, Looks like Jeff already knew that. :shock:
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Move object to layers
« Reply #14 on: February 22, 2005, 03:58:58 PM »
Quote from: Jeff_M
Mark meant to use sslength but inadvertently used length. Change that and it will work.

Past due reply to follow

Thanks for pointing that out Jeff.
TheSwamp.org  (serving the CAD community since 2003)