Author Topic: Simple routine request  (Read 6640 times)

0 Members and 1 Guest are viewing this topic.

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.