TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: CAB on January 06, 2004, 09:18:46 PM

Title: v-lisp & layout tabs
Post by: CAB on January 06, 2004, 09:18:46 PM
I am trying to set the PSLTSCALE to zero in each layout.
The following code seems to work although it is slow.
Stepping through each layout and making it current is a slow process.
Is there a way to set the variable transparently?
Also is there a way to use vla-put to set this variable?

Thanks CAB

Code: [Select]

;;  Function to set line scale in all tabs
(defun LayoutLineScale (/ tab)
  (vl-load-com)

  (and
    (or *acad* (setq *acad* (vlax-get-acad-object)))
    (or *doc* (setq *doc* (vla-get-activedocument *acad*)))
    (or *layouts* (setq *layouts* (vla-get-layouts *doc*)))
  )
   ;; step through each layout except MODEL space
  (foreach tab (vl-remove "Model" (layoutlist))
    ; set tab current
    ;(vlax-put-property document 'ActiveLayout (vla-item *layouts* tab))
    (vla-put-activelayout *doc* (vla-item *layouts* tab))
    (setvar "PSLTSCALE" 0)
  )


) ; End Plot_config_list
(defun c:LSS ()
  (LayoutLineScale)
)
Title: v-lisp & layout tabs
Post by: Keith™ on January 06, 2004, 11:11:20 PM
Well, I looked at it over and over again and it seems that the variable data is stored in the Layout object list, but while you can change it directly, it will not become active unless you switch the layout... now how silly is that. The DXF code is automatically updated to the value of PSLTSCALE only when the layout is changed, so if you changed the layout directly via lisp, the PSLTSCALE will still be the other setting until you switched the layout, at which point the layout is updated to the value of PSLTSCALE which defeats the purpose all together. There may not be a simple answer, but I have not yet given up hope.
Title: v-lisp & layout tabs
Post by: CAB on January 06, 2004, 11:20:26 PM
Well you've gotten a lot farther than I did.

Thanks for the effort.

CAB
Title: v-lisp & layout tabs
Post by: Keith™ on January 06, 2004, 11:43:55 PM
Ok, it ain't pretty but it works....

Code: [Select]

;;;  Function to set line scale in all tabs
(defun LayoutLineScale ( / pslist psltval tab)
  (vl-load-com)
  (and
    (or *acad* (setq *acad* (vlax-get-acad-object)))
    (or *doc* (setq *doc* (vla-get-activedocument *acad*)))
    (or *layouts* (setq *layouts* (vla-get-layouts *doc*)))
  );_and
  ;;set PSLTSCALE to 0 in ModelSpace
  (vla-setvariable *doc* "PSLTSCALE" 0)
  ;;cycle through all but model tab
  (foreach tab (vl-remove "Model" (layoutlist))
    ;;extract the data list and reverse it
    (setq pslist (reverse (entget (vlax-vla-object->ename(vla-item *layouts* tab)))))
    ;;grab the value of PSLTSCALE for that layout tab
    (setq psltval (cdr (assoc 70 pslist)))
    ;;based on it's setting lets reduce it by 1
    ;; 0 = PSLTSCALE off and LIMCHECK off
    ;; 1 = PSLTSCALE on  and LIMCHECK off
    ;; 2 = PSLTSCALE off and LIMCHECK on
    ;; 3 = PSLTSCALE on  and LIMCHECK on
    (cond
      ;; PSLTSCALE is already off so ignore
      ((= psltval 0) nil)
      ;; PSLTSCALE is on so turn it off
      ((= psltval 1)(entmod (reverse (subst (cons 70 0)(assoc 70 pslist)pslist))))
      ;; PSLTSCALE is already off so ignore
      ((= psltval 2) nil)
      ;; PSLTSCALE is on so turn it off
      ((= psltval 3)(entmod (reverse (subst (cons 70 2)(assoc 70 pslist)pslist))))
    );_cond
  );_foreach
);_defun LayoutLineScale


The trick was to set the value of PSLTSCALE in modelspace, then the PSLTSCALE changes would take effect.
Title: v-lisp & layout tabs
Post by: CAB on January 07, 2004, 12:02:04 AM
Well kiss my grits, you got it.

I didn't think it was possible.

Just goes to show you, the impossible just takes a little longer. :)


Thanks  K

CAB
Title: v-lisp & layout tabs
Post by: Keith™ on January 07, 2004, 12:09:45 AM
Quote from: CAB
Just goes to show you, the impossible just takes a little longer.


That is what I figured....which is why I never gave up hope....
Title: v-lisp & layout tabs
Post by: daron on January 07, 2004, 09:43:20 AM
Well CAB, it seems that you are really starting to get the hang of ActiveX. Good work.
Title: v-lisp & layout tabs
Post by: CAB on January 07, 2004, 10:42:53 AM
Well you know I read the book, read Mark's Help file, read the book, read Mark's Help file,
 read the book, read Mark's Help file, read the book, read Mark's Help file. :)

And THEN just started trying to code and only then did it start to click.
I've only opened the door so I got a ways to go...

CAB
Title: v-lisp & layout tabs
Post by: daron on January 07, 2004, 10:45:34 AM
Quote from: CAB
And THEN just started trying to code and only then did it start to click.

That's the only way it ever does.
Title: v-lisp & layout tabs
Post by: Columbia on January 07, 2004, 10:51:40 AM
The only thing that I would like to add to this topic is a little bit of a warning with vla-put and vla-get.  I have had some experience where vla-put was not recognized with some properties.  I'm having trouble remembering exactly which one, but I think it had to do with the true color stuff in AutoCAD 2004.  Therefore, I don't recommend using it.  I do recommend using the vlax-put-property or vlax-get-property.  I know it's a little more wordy, however I haven't had any other problems like I did with vla-put and vla-get.
Title: v-lisp & layout tabs
Post by: Keith™ on January 07, 2004, 12:01:17 PM
vla- commands are simply VBA commands with vla- prefixed on the command, plus a read-write property is made as vla-get- and vla-put

Incedently you can expand the Visual Lisp command set simply by importing the type library.
Title: v-lisp & layout tabs
Post by: Mark on January 07, 2004, 01:40:01 PM
If you plan on using vlisp to say...read write data from Excel you will have to use vlax-get-property and vlax-put-property so you you might as well use them all the time. :D
Title: v-lisp & layout tabs
Post by: JohnK on January 07, 2004, 01:51:47 PM
I covered the diffrences between the two in my Ninja training.

The "vla" prefix is used for accessing methods and properties of ActiveX objects.
The "vlax" prefix is a general prefix used for other ActiveX objects. (like word, excel, …Other applications in general.) You use this prefix to get/put properties of other ActiveX objects.