Author Topic: How to fix this code...  (Read 2812 times)

0 Members and 1 Guest are viewing this topic.

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
How to fix this code...
« on: November 30, 2015, 10:07:37 AM »
I tried to improve program (see attached lisp file), but have some issues with it..

This program export layout names to excel file with dimension of each layouts (paper size)

Program working properly but have a real problem with functionality. I mean program return only

Dimensions of CURRENT TAB, but I need it for each one of layouts. I think, function (papersize) working only for current tab so I can’t to invoke this function for each one of tabs..

Can somebody fix it?

Any help will be very appreciated

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: How to fix this code...
« Reply #1 on: November 30, 2015, 11:50:12 AM »
...not tested:

Code: [Select]
; get paper size on current tab
(defun papersize (TabNam / psn scale) ; <<<
  (setq
    psn (member '(100 . "AcDbPlotSettings")
(dictsearch
  (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_LAYOUT")))
  TabNam ; <<<
)
)
  )
...
Code: [Select]
...
         (vlax-for olayout olayouts
            (if (/= "Model" (setq layoutname (vla-get-name olayout)))
                  (bbox:writedata layoutname (papersize layoutname) file)  ; <<<               )
            )
         )
...

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: How to fix this code...
« Reply #2 on: December 01, 2015, 01:00:27 AM »
Thank you for your replay Marc'Antonio Alessi
but I still have a problem: After your changes program return
"
** Error: bad argument type: stringp nil **"
(see attached lisp code)

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: How to fix this code...
« Reply #3 on: December 01, 2015, 01:18:21 AM »
Another way to make one step to solution of this issue is - to invoke this function instead of internal function (papersize) (see attached lisp)
But in this case I need variable as name of layout..
somefing like this:

(plotpapersize(layoutget "layout name"))

..and make the loop from first layoyt to last..
Can somebody help me?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How to fix this code...
« Reply #4 on: December 01, 2015, 03:45:37 AM »
The problem seems to be that the (papersize) function looks in the (namedobjdict) of the current document and the layout objects can come from an external 'DBX' document.

Revised function:
Code - Auto/Visual Lisp: [Select]
  1. ; Argument: olayout - Layout object.
  2. (defun papersize (olayout / elst scale)
  3.   (setq elst (entget (vlax-vla-object->ename olayout)))
  4.   (setq scale (if (= 0 (cdr (assoc 72 elst))) 25.4 1.0))
  5.   (strcat
  6.     (rtos (/ (cdr (assoc 44 elst)) scale) 2 2)
  7.     " x "
  8.     (rtos (/ (cdr (assoc 45 elst)) scale) 2 2)
  9.   )
  10. )

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: How to fix this code...
« Reply #5 on: December 01, 2015, 04:01:42 AM »
Thank you for your replay Roy_043.
Probably we have here another additional problem..
If we invoke (papersize) function according to your changes (see attached lisp)
we receive following error:
"** Error: bad argument type: VLA-OBJECT "Layout1" **"

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How to fix this code...
« Reply #6 on: December 01, 2015, 05:21:30 AM »
The function is my previous post requires a layout OBJECT argument.

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: How to fix this code...
« Reply #7 on: December 01, 2015, 05:40:13 AM »
It's not clearly understood for me.. Can you publish your code.. how you can see it.
Thank you

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How to fix this code...
« Reply #8 on: December 01, 2015, 05:55:50 AM »
Change:
Code: [Select]
(bbox:writedata layoutname (papersize layoutname) file)To:
Code: [Select]
(bbox:writedata layoutname (papersize olayout) file)

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: How to fix this code...
« Reply #9 on: December 01, 2015, 06:14:06 AM »
Thank you very much Roy_043
Now program become useful!
Only two questions remain for me..
1.In excel table you can see information about two empty layouts “Layout1” and “Layout2” with sizes 0x0
Is it possible to eliminate this information from the table (answer “manually” not accepted :smitten:)?
2.In table you receive information about paper sizes of each one of layouts.. Is it possible to receve information about REAL PRINTABLE AREA in these layouts?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How to fix this code...
« Reply #10 on: December 01, 2015, 08:08:01 AM »
#1:
Change
Code: [Select]
(foreach dwg dwgs   ; edited here (cdr dwgs)To:
Code: [Select]
(foreach dwg (cdr dwgs)
#2:
You should try this yourself.
In the entity list of the layout group codes 40-43 provide unprintable margin information.

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: How to fix this code...
« Reply #11 on: December 01, 2015, 08:19:36 AM »
Thank you Roy_43!
1. Working properly as I like it!
2. Where can I find the source of information about layout group codes 40-43 and the way of change it via lisp?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How to fix this code...
« Reply #12 on: December 01, 2015, 08:31:50 AM »
http://images.autodesk.com/adsk/files/autocad_2012_pdf_dxf-reference_enu.pdf

To change entity lists the (entmod) function can be used. Although the print margins are typically hardware dependent.

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: How to fix this code...
« Reply #13 on: December 01, 2015, 08:36:43 AM »
Thank you Roy_43.. I'll try it shortly..