Author Topic: Simple routine request  (Read 6650 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Simple routine request
« on: June 18, 2010, 08:12:15 AM »
Hi all

I want to select an object in all layouts then change entity for?

Example

select all viewports in all layouts
save old value of DXF code 90
add 147456 to old value

thanks for your help
Hasan

kpblc

  • Bull Frog
  • Posts: 396
Re: Simple routine request
« Reply #1 on: June 18, 2010, 08:32:14 AM »
You can use something like (setq selset (ssget "_X" '((0 . "VIEWPORT")))) and work with selection set.
Sorry for my English.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Simple routine request
« Reply #2 on: June 18, 2010, 03:35:43 PM »
thanks kpblc

this was my start
Code: [Select]
(defun c:vps ()
     (setq vprtslct (ssget "X" '((0 . "VIEWPORT"))))
     (foreach x vprtslct
      )
but I lost in foreach and How to select viewport in all layouts.
 

PS: Whats deference between "X" and "_X"

Hasan
« Last Edit: June 18, 2010, 03:46:12 PM by HasanCAD »

kpblc

  • Bull Frog
  • Posts: 396
Re: Simple routine request
« Reply #3 on: June 18, 2010, 03:51:30 PM »
The difference is:
(ssget "X" <...>) -> will work only on english AutoCAD
(ssget "_X" <...>) -> will work on any localised version of AutoCAD (include English)
P.S. To convert selection set to list try to use code like this:
Code: [Select]
(defun conv-selset-to-list (selset / tab item)
  (repeat (setq tab  nil
                item (sslength selset)
                ) ;_ end setq
    (setq tab (cons (ssname selset (setq item (1- item))) tab))
    ) ;_ end of repeat
  ) ;_ end of defun
And then:
Code: [Select]
(setq vprtslct (ssget "_X" '((0 . "VIEWPORT"))))
(foreach (conv-selset-to-list vprtslct)
<...>
  )
Sorry for my English.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Simple routine request
« Reply #4 on: June 18, 2010, 07:26:28 PM »

Quote
(ssget "X" <...>) -> will work only on english AutoCAD
(ssget "_X" <...>) -> will work on any localised version of AutoCAD (include English)

Can someone confirm that the (ssget "X" .. is affected by ' localisation ' issues
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

kenkrupa

  • Newt
  • Posts: 84
Re: Simple routine request
« Reply #5 on: June 19, 2010, 12:03:46 PM »
Can someone confirm that the (ssget "X" .. is affected by ' localisation ' issues

Command: (ssget "X")
<Selection set: 3>

Command: globcheck
Enter new value for GLOBCHECK <0>: 1

Command: (ssget "X")
The ssget option string must be preceded by an underscore.
Localization unfriendly ssget option "x" rejected!

kpblc

  • Bull Frog
  • Posts: 396
Re: Simple routine request
« Reply #6 on: June 19, 2010, 01:24:58 PM »
I can't find full description of system variable 'globcheck'. Could you help me please?
Sorry for my English.

LE3

  • Guest
Re: Simple routine request
« Reply #7 on: June 19, 2010, 01:31:56 PM »
I can't find full description of system variable 'globcheck'. Could you help me please?

Here:
http://www.manusoft.com/resources/acadexposed/sysvars.html

kpblc

  • Bull Frog
  • Posts: 396
Re: Simple routine request
« Reply #8 on: June 19, 2010, 01:44:43 PM »
Thank you very much!
Sorry for my English.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Simple routine request
« Reply #9 on: June 24, 2010, 03:50:17 AM »
(defun c:vps(/ dimsel)
(setq dimsel(ssget "x" '((0 . "VIEWPORT"))))
   (command "_PSELECT" "_p" "")
(PRINC)
)
selected all viewports in all layouts

but entmod not working with viewports
is there any solution?
« Last Edit: June 24, 2010, 03:56:35 AM by HasanCAD »

Hangman

  • Swamp Rat
  • Posts: 566
Re: Simple routine request
« Reply #10 on: June 24, 2010, 02:40:52 PM »
Quote
AutoLISP Reference Guide > AutoLISP Functions > E Functions >

entmod

Modifies the definition data of an object (entity)
 <...>

Restrictions on Using entmod

There are restrictions on the changes the entmod function can make:
<...>
*** You cannot use the entmod function to modify a viewport entity. ***


Sorry, no-can-do with Entmod.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hangman

  • Swamp Rat
  • Posts: 566
Re: Simple routine request
« Reply #11 on: June 24, 2010, 02:45:33 PM »
Here's an excerpt taken from CAB's 'VPLockAll',
Code: [Select]
(if (= (vla-get-objectname ent) "AcDbViewport")
          (progn
            (vla-put-displaylocked ent lck)
            (vla-put-color ent clr)
            (if (setq obj (assoc 340  (entget (vlax-vla-object->ename ent))))
              (vla-put-color (vlax-ename->vla-object (cdr obj)) clr2)
            )
          ); end progn
        )

I know the viewport is accessed and it is locked or unlocked, and the color is changed depending on the scenario, but this is the only manner I have seen so far in modifying viewports.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Simple routine request
« Reply #12 on: July 02, 2010, 09:31:20 AM »
what about this

Code: [Select]
(defun c:vps(/ VPsel)

  (foreach x (setq VPsel(ssget "_X" '((0 . "VIEWPORT"))))
    (vla-put-displaylocked VPsel :vlax-false)
            )
  (PRINC)
  )

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Simple routine request
« Reply #13 on: July 02, 2010, 09:34:23 AM »
what about this

Code: [Select]
(defun c:vps(/ VPsel)

  (foreach x (setq VPsel(ssget "_X" '((0 . "VIEWPORT"))))
    (vla-put-displaylocked VPsel :vlax-false)
            )
  (PRINC)
  )

You'll have to turn your selection set into a list to perform foreach on it.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Simple routine request
« Reply #14 on: July 02, 2010, 09:40:31 AM »
You'll have to turn your selection set into a list to perform foreach on it.

Is this correct way
Code: [Select]
(defun c:vps(/ VPsel)

  (foreach x (setq VPsel (list (ssget "_X" '((0 . "VIEWPORT")))))
    (vla-put-displaylocked VPsel :vlax-false)
            )
  (PRINC)
  )
seems not
because not working for me

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Simple routine request
« Reply #15 on: July 02, 2010, 09:50:51 AM »
You'll have to turn your selection set into a list to perform foreach on it.

Is this correct way
Code: [Select]
(defun c:vps(/ VPsel)

  (foreach x (setq VPsel (list (ssget "_X" '((0 . "VIEWPORT")))))
    (vla-put-displaylocked VPsel :vlax-false)
            )
  (PRINC)
  )
seems not
because not working for me

Try this:

Code: [Select]
(defun c:vps (/ n ss)
  (setq n -1)
  (if (setq ss (ssget "_X" '((0 . "VIEWPORT"))))
    (while (setq e (ssname ss (setq n (1+ n))))
      (vla-put-displaylocked (vlax-ename->vla-object e) :vlax-false)
    )
  )
  (princ)
)

On a side note ... have you done a search on the forum? There are numerous examples of dealing with selection sets and modifying viewports.
« Last Edit: July 02, 2010, 09:54:04 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Simple routine request
« Reply #16 on: July 02, 2010, 10:41:37 AM »
Here is an example:

Code: [Select]
(defun c:ToColor (/ time ss)
  (setq time (getvar "millisecs"))
  (if (setq ss (ssget "_X"))
    (progn
       (vlax-for x (setq ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
         (vla-put-color x 251))
      (vla-delete ss)))
    (princ (strcat "\n<< FULL ActiveX took: " (rtos (/ (- (getvar "millisecs") time) 1000.) 2 4) " secs. >>"))
  (princ))
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.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Simple routine request
« Reply #17 on: July 03, 2010, 08:11:31 AM »
On a side note ... have you done a search on the forum? There are numerous examples of dealing with selection sets and modifying viewports.

First of all thanks for you and CAB for helping

second
- I did but I am new in coding and some times I confused. So I want to start from the beginning so understand every thing step by step.
- Some times the conversation comes very reach and gives a lot of tricks and ideas. for example you and CAB did the same thing with 2 different ways. and CAB added a new trick (new for me) How to calculate processing time. Long time ago I want to know how to calculate the process time. finally I got it.

Finally Thanks again for all
HasanCAD

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Simple routine request
« Reply #18 on: July 03, 2010, 08:16:53 AM »
Glad we could help you on your journey.  :-)
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.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Simple routine request
« Reply #19 on: July 04, 2010, 04:40:24 AM »
this is final code

Code: [Select]
(defun *error* (msg)
    (and uFlag (vla-EndUndoMark doc))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ))

(defun c:vpslct (/ n ss)
  (vl-load-com)

  (setq doc (cond (doc) ((vla-get-ActiveDocument
                           (vlax-get-Acad-Object))))
        spc (if (zerop (vla-get-activespace doc))
              (if (= (vla-get-mspace doc) :vlax-true)
                (vla-get-modelspace doc)
                (vla-get-paperspace doc))
              (vla-get-modelspace doc))
        time (getvar "millisecs")
        n -1
        )

  (if (setq ss (ssget "_X" '((0 . "VIEWPORT"))))
    (while (setq e (ssname ss (setq n (1+ n))))
      (vla-put-displaylocked (vlax-ename->vla-object e) :vlax-true)
      (vla-put-ViewportOn (vlax-ename->vla-object e) :vlax-true)
      )
    )
  (princ (strcat "\n<< FULL ActiveX took: " (rtos (/ (- (getvar "millisecs") time) 1000.) 2 4) " secs. >>"))
  (princ)
  )

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Simple routine request
« Reply #20 on: July 04, 2010, 05:22:18 AM »

Quote
(ssget "X" <...>) -> will work only on english AutoCAD
(ssget "_X" <...>) -> will work on any localised version of AutoCAD (include English)

Can someone confirm that the (ssget "X" .. is affected by ' localisation ' issues

(ssget "X") works with a French version but some other options don't ("WP" or ":S" for instance).
So, I always 'internationalize' the selection mode string.
« Last Edit: July 04, 2010, 05:31:14 AM by gile »
Speaking English as a French Frog

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Simple routine request
« Reply #21 on: July 04, 2010, 05:33:32 AM »


This may be better for you :--
Code: [Select]
(defun c:vpslct (/ n ss *error*)
  (vl-load-com)
  (defun *error* (msg)
      (and uFlag (vla-EndUndoMark doc))
      (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
          (princ (strcat "\n** Error: " msg " **")))
      (princ)
  )
  ;; code mojo follows ...
(princ)
)
 
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.