Author Topic: Page Setup group codes?  (Read 3182 times)

0 Members and 1 Guest are viewing this topic.

qwrtz

  • Guest
Page Setup group codes?
« on: March 10, 2008, 08:38:32 PM »
Is it possible to change a Page Setup by its group codes?

I'd like to make a lisp command that turns on "Display Plot Styles" for all layout tabs in a file, without changing any other Page Setup parameters.

I can't find it in the group code reference manual, but by looking at DXF ASCII versions of drawing files, I found that group code (70 . 690) turns on "Display Plot Styles". In some cases I may also want to change the printer name and size, which are apparently group codes 2 and 4 respectively.

But I don't know how to select all the page setups and change their group codes.

Any ideas?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Page Setup group codes?
« Reply #1 on: March 10, 2008, 11:42:15 PM »
Group code 70 hosts the state of ShowPlotStyles as a bit code integer per this table:

Code: [Select]
    1 = PlotViewportBorders
    2 = ShowPlotStyles
    4 = PlotCentered
    8 = PlotHidden
   16 = UseStandardScale
   32 = PlotPlotStyles
   64 = ScaleLineweights
  128 = PrintLineweights
  512 = DrawViewportsFirst
 1024 = ModelType
 2048 = UpdatePaper
 4096 = ZoomToPaperOnUpdate
 8192 = Initializing
16384 = PrevPlotInit

I took a snapshots of the dxf codes for a layout with ShowPlotStyles set to false and true respectively to confirm the difference is limited to the 70 group:

Code: [Select]
(progn
    (mapcar
       '(lambda (x)
            (print x)
            (princ
                (if (apply 'equal x)
                   'same
                   'different
                )
            )
        )
        (mapcar 'list data1 data2)
    )   
    (princ)
)

Result:

Code: [Select]
((-1 . <Entity name: 7ef9ed10>) (-1 . <Entity name: 7ef9ed10>)) SAME
((0 . "LAYOUT") (0 . "LAYOUT")) SAME
((5 . "22") (5 . "22")) SAME
((102 . "{ACAD_REACTORS") (102 . "{ACAD_REACTORS")) SAME
((330 . <Entity name: 7ef9ecd0>) (330 . <Entity name: 7ef9ecd0>)) SAME
((102 . "}") (102 . "}")) SAME
((330 . <Entity name: 7ef9ecd0>) (330 . <Entity name: 7ef9ecd0>)) SAME
((100 . "AcDbPlotSettings") (100 . "AcDbPlotSettings")) SAME
((1 . "") (1 . "")) SAME
((2 . "none_device") (2 . "none_device")) SAME
((4 . "ISO_A4_(210.00_x_297.00_MM)") (4 . "ISO_A4_(210.00_x_297.00_MM)")) SAME
((40 . 7.5) (40 . 7.5)) SAME
((41 . 20.0) (41 . 20.0)) SAME
((42 . 7.5) (42 . 7.5)) SAME
((43 . 20.0) (43 . 20.0)) SAME
((44 . 210.0) (44 . 210.0)) SAME
((45 . 297.0) (45 . 297.0)) SAME
((46 . 11.55) (46 . 11.55)) SAME
((47 . -13.65) (47 . -13.65)) SAME
((48 . 0.0) (48 . 0.0)) SAME
((49 . 0.0) (49 . 0.0)) SAME
((140 . 0.0) (140 . 0.0)) SAME
((141 . 0.0) (141 . 0.0)) SAME
((142 . 1.0) (142 . 1.0)) SAME
((143 . 8.70408) (143 . 8.70408)) SAME
((70 . 11952) (70 . 11954)) [color=red]DIFFERENT[/color]
((72 . 1) (72 . 1)) SAME
((73 . 0) (73 . 0)) SAME
((74 . 0) (74 . 0)) SAME
((7 . "") (7 . "")) SAME
((75 . 0) (75 . 0)) SAME
((147 . 0.114889) (147 . 0.114889)) SAME
((76 . 0) (76 . 0)) SAME
((77 . 2) (77 . 2)) SAME
((78 . 300) (78 . 300)) SAME
((148 . 0.0) (148 . 0.0)) SAME
((149 . 0.0) (149 . 0.0)) SAME
((100 . "AcDbLayout") (100 . "AcDbLayout")) SAME
((1 . "Model") (1 . "Model")) SAME
((70 . 1) (70 . 1)) SAME
((71 . 0) (71 . 0)) SAME
((10 0.0 0.0 0.0) (10 0.0 0.0 0.0)) SAME
((11 12.0 9.0 0.0) (11 12.0 9.0 0.0)) SAME
((12 0.0 0.0 0.0) (12 0.0 0.0 0.0)) SAME
((14 0.0 0.0 0.0) (14 0.0 0.0 0.0)) SAME
((15 0.0 0.0 0.0) (15 0.0 0.0 0.0)) SAME
((146 . 0.0) (146 . 0.0)) SAME
((13 0.0 0.0 0.0) (13 0.0 0.0 0.0)) SAME
((16 1.0 0.0 0.0) (16 1.0 0.0 0.0)) SAME
((17 0.0 1.0 0.0) (17 0.0 1.0 0.0)) SAME
((76 . 0) (76 . 0)) SAME
((330 . <Entity name: 7ef9ecf8>) (330 . <Entity name: 7ef9ecf8>)) SAME
((331 . <Entity name: 7ef9ef50>) (331 . <Entity name: 7ef9ef50>)) SAME

As noted, the 70 group is a bit coded integer. To turn on ShowPlotStyles perform a 'bitwise or' (see the logior function) with the existing value and 2; to remove it perform an 'exclusive or' (see boole function) with same.

Having said all that I'd encourage you to do it via activex rather than dxf.

For example, turn on ShowPlotStyles for all layouts ...

Code: [Select]
(vlax-for layout (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
    (vla-put-ShowPlotStyles layout :vlax-true)
)

Was there a specific reason why you wanted to do it via dxf?

(Hope this was coherent, I'm a bit into a sleeping pill; apologies if it ain't).
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Page Setup group codes?
« Reply #2 on: March 11, 2008, 04:25:31 AM »

I took a snapshots < snip >
Code: [Select]
(progn
   ;;................
    (princ)
)

Result:

< snip>

nice bit of functional code Michael .. :-)

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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Page Setup group codes?
« Reply #3 on: March 11, 2008, 08:43:47 AM »
nice bit of functional code Michael ..

Thanks Kerry. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

qwrtz

  • Guest
Re: Page Setup group codes?
« Reply #4 on: March 11, 2008, 10:06:02 AM »
Thank you, MP, for a very comprehensive answer, which solved my problem and also introduced me to a lot of new concepts.

The only reason I was trying to do it with group codes is that's all I know. I learned lisp on Release 10 and never went beyond that. I was wondering what all this vla- stuff was. It sounded extra-terrestrial. But I'll definitely try to learn something about it now. That short code you wrote to show plotstyles is so much simpler than what I thought I'd have to do.

And I've always wanted to take a snapshot of group codes like that. Very nice! But I don't see anything in that code about selecting a layout. Data1 and data2 just look like variables. How did you get the two layouts in there?

What I've been doing till now is saving a file as DXF-text and then pawing through it with a word processor. Crude, yes, but that's where I found the 690. All the layouts I looked at had a 688 or 692 following the 70 if Display Plotstyles was off, and a 690 if it was on. That matches up with the bitcoding system you showed, since 512 + 128 + 32 + 16 + 2 = 690. I found that if I changed the 688's and 692's (only when preceded by 70, CR, and three spaces) to 690's using the word processor's Replace function, that did what I wanted. But I see now that I was unknowingly removing the bitcode 4 from the 692's. And of course a lot of time is wasted saving each file as DXF-text, and then opening it in Atlantis, and then saving it and going back to DWG format.

Again, many thanks for a solution and a quantum leap in my knowledge of lisp.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Page Setup group codes?
« Reply #5 on: March 11, 2008, 11:25:50 AM »
Glad you found some of the info helpful Qwrtz. I'm slammed at work and don't have the benefit of enough time to respond to your questions to the fullness they deserve until tonight. In the interim these tools might help somewhat:

Info.vlx - utility to easily view both the ActiveX properties as well as DXF group codes.
Elist.lsp - provides similarly formatted output but only for DXF group codes.

My pleasure to try and help out. You will soon see that there are a lot of folks with tremendous lisp expertise that hang their hat at the swamp. I'm happy just to get to run with them. Cheers and good luck with your endeavors.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

qwrtz

  • Guest
Re: Page Setup group codes?
« Reply #6 on: March 11, 2008, 11:12:55 PM »
Thanks for the references, MP. I'm going to have to buy a book on using Vlisp. There doesn't seem to be as much on the internet about it as there is about old lisp.

In the meantime, is there an easy way to modify that function so that it doesn't apply to the model tab? I only wanted to show plotstyles in the layout tabs. Or maybe another function that I can include after it to turn it off in the model tab?

Your original function:
Code: [Select]
(vlax-for layout (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
    (vla-put-ShowPlotStyles layout :vlax-true)
)

I read at another web site that there's a (LayoutList) function that selects only the layout tabs, whereas (vla-get-layouts) selects the model tab, too. But I can't find anything else about the (LayoutList) function, and I have no idea how or if it could be used in your function.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Page Setup group codes?
« Reply #7 on: March 11, 2008, 11:58:52 PM »
Not that I'm qualified, but if I had the time and economic situation to support I'd love to write a HCVL book ...

... anyway, back from dreams. Some brief, hopefully illuminating code.

;;  We're going to use the layouts collection a couple times,
;;  so one way we could make things easier for ourself is to
;;  save a reference to the layouts collection.

;;  Suggestion, read about the layouts collection in the VBA
;;  reference. Even though it is VBA and not LISP it will
;;  give you some background on the object model. Feel free
;;  to read about other things in the VBA reference because
;;  you will spend a lot of time there if you want to do Visual
;;  LISP effectively. Anyway ...


(setq layouts
    (vla-get-layouts
        (vla-get-activedocument
            (vlax-get-acad-object)
        )
    )
)

;;  Let's print out the all properties for each layout. In
;;  the interests of brevity we're not going to show the
;;  methods available, just the properties.

;;  Suggestion, read about the vlax-for and vlax-dump-object
;;  functions in the AutoLISP reference.


(vlax-for layout layouts
    (vlax-dump-object layout)
)

<big dump excluded from this post>

;;  Maybe you noticed each layout object has a name property.
;;  Let's print them all out so they're easier to see away from
;;  the massive properties dump we did previously.


(vlax-for layout layouts
    (print (vla-get-name layout))
)

"Layout1"
"Layout2"
"Model"


;;  Ok. Having done that let's selectively act upon the viewports,
;;  if it's the modelspace layout let's turn off ShowPlotStyles,
;;  otherwise let's turn them on.


(vlax-for layout layouts
    (vla-put-ShowPlotStyles layout
        (if (eq "Model" (vla-get-name layout))
            :vlax-false
            :vlax-true
        )   
    )       
)

;;  Show the state now for each layout object

(progn
    (vlax-for layout layouts   
        (mapcar
           '(lambda ( property )
                (print
                    (strcat
                        (vl-symbol-name property)
                        " = "
                        (vl-princ-to-string (vlax-get-property layout property))
                    )
                )
                (princ "\n")       
            )
           '(Name ShowPlotStyles)
        )
    )   
    (princ)
)   

"NAME = Layout1"
"SHOWPLOTSTYLES = :vlax-true"
"NAME = Layout2"
"SHOWPLOTSTYLES = :vlax-true"
"NAME = Model"
"SHOWPLOTSTYLES = :vlax-false"


;;  Hope it helps ... happy reading ... come back again :)
« Last Edit: March 12, 2008, 12:03:50 AM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

qwrtz

  • Guest
Re: Page Setup group codes?
« Reply #8 on: March 12, 2008, 11:30:17 AM »
Yes, it helps a lot. Thanks very much.
I see that this time you first compiled a list of layouts in the active drawing, and assigned it to the variable "layouts", and then called that variable to process the list. In the original code you skipped the variable and just used the whole list-compiling function as the second argument to the (vlax-for) function.
And I see now that these VLA functions are just lisp functions that have long, strange names, and that aren't included in my old programmer's reference. I'll just have to buy a new book, so I can follow the rest of what you wrote.
Thanks again for all your help.
« Last Edit: March 13, 2008, 09:24:42 AM by qwrtz »