Automatic Papersize

Automatic Papersize

thomas_schluesselberger
Advocate Advocate
10,745 Views
93 Replies
Message 1 of 94

Automatic Papersize

thomas_schluesselberger
Advocate
Advocate

Hi!

 

I don't think there is a solution for this, but please convince me otherwise:

 

I would like a LISP program that allows me to automatically crop the paper sizes of all layouts. So the paper size should automatically adapt to the objects in the layout. So that there is no white border outside the viewport.

I would then like to create pdfs with "publish" as normal, but I don't want to have to crop the PDF every time.

 

Until now i always have to manually create a new paper size and set each layout individually.

 

0 Likes
Accepted solutions (1)
10,746 Views
93 Replies
Replies (93)
Message 21 of 94

thomas_schluesselberger
Advocate
Advocate

Hi!

 

The pc3 file is added correctly.

I tested it again, I drew a rectangle that is 2000x900mm in size in a layout and created a suitable paper format for it. But I always get the following error message:

 

Layout1
* Automation Error Invalid Input *
fail to set media size UserDefinedMetric (914 x 2100MM) in Layout1 layout.

 

 

0 Likes
Message 22 of 94

Moshe-A
Mentor
Mentor

@thomas_schluesselberger,

 


@thomas_schluesselberger wrote:

Hi!

 

The pc3 file is added correctly.

I tested it again, I drew a rectangle that is 2000x900mm in size in a layout and created a suitable paper format for it. But I always get the following error message:

 

Layout1
* Automation Error Invalid Input *
fail to set media size UserDefinedMetric (914 x 2100MM) in Layout1 layout.

 

 


Are you taking in consideration when you specifies a 2100x914 units rectangle to be plotted you need a bigger media size? make room for margin to leave - Ha 🤣

 

Are you using my PDF to DWG - MPS.pc3? did you add media size to it?

 

to be succees in this you need to play with my pc3 + mpsetup.dwg untill you achieve what you want, do not challange it with other media sizes or your drawings.

 

And if it still doesn't work, post your pc3 + dwg

i promise,  we will make it work by 'hook or by crook' 😀😁😂🤣

 

Moshe

 

 

 

 

 

0 Likes
Message 23 of 94

thomas_schluesselberger
Advocate
Advocate



Are you taking in consideration when you specifies a 2100x914 units rectangle to be plotted you need a bigger media size? make room for margin to leave - Ha 🤣

I don't want to have margin. I want it to crop perfectly to the rectangle.

 

Are you using my PDF to DWG - MPS.pc3? did you add media size to it?

Yes i'm using your pc3. What do you mean by media size? Is that the paper format/size which i have to add before?

 

to be succees in this you need to play with my pc3 + mpsetup.dwg untill you achieve what you want, do not challange it with other media sizes or your drawings.

Your rectangles are all smaller than the actual size of the respective paper format. Example: The A4 (Landscape) layout has a rectangle that is 277.1243mm x 168.8432mm. Does this have a reason?

 

And if it still doesn't work, post your pc3 + dwg

i promise,  we will make it work by 'hook or by crook' 😀😁😂🤣

 

Must the paper format name be exactly as in the video?

Or maybe there is some problem because my AutoCAD is in german?

 

 

0 Likes
Message 24 of 94

Moshe-A
Mentor
Mentor

@thomas_schluesselberger 

 


@thomas_schluesselberger wrote:



Are you taking in consideration when you specifies a 2100x914 units rectangle to be plotted you need a bigger media size? make room for margin to leave - Ha 🤣

I don't want to have margin. I want it to crop perfectly to the rectangle.

Opa, this is the first time you say that?! 

MPSETUP do not set (change) the default margin so a fix here is needed.

 

Are you using my PDF to DWG - MPS.pc3? did you add media size to it?

Yes i'm using your pc3. What do you mean by media size? Is that the paper format/size which i have to add before?

i asked that cause you said the system admin doesn't allow me to copy outside pc3 files?!

 

to be succees in this you need to play with my pc3 + mpsetup.dwg untill you achieve what you want, do not challange it with other media sizes or your drawings.

Your rectangles are all smaller than the actual size of the respective paper format. Example: The A4 (Landscape) layout has a rectangle that is 277.1243mm x 168.8432mm. Does this have a reason?

yes margins

 

And if it still doesn't work, post your pc3 + dwg

i promise,  we will make it work by 'hook or by crook' 😀😁😂🤣

 

Must the paper format name be exactly as in the video? YES YES YES

Or maybe there is some problem because my AutoCAD is in german?

 

 


So only for a test sake, play with my rectangles make them a bit smaller and use my media sizes. i need you to say YES IT IS WORKING and then we will go from there.

 

 

0 Likes
Message 25 of 94

thomas_schluesselberger
Advocate
Advocate

Are you taking in consideration when you specifies a 2100x914 units rectangle to be plotted you need a bigger media size? make room for margin to leave - Ha 🤣

I don't want to have margin. I want it to crop perfectly to the rectangle.

Opa, this is the first time you say that?!  In exactly this wording it is the first time 😂

MPSETUP do not set (change) the default margin so a fix here is needed.

 

 

Are you using my PDF to DWG - MPS.pc3? did you add media size to it?

Yes i'm using your pc3. What do you mean by media size? Is that the paper format/size which i have to add before?

i asked that cause you said the system admin doesn't allow me to copy outside pc3 files?!

Yeah i know, at first i didnt knew where to put the pc3 and i googled which folder i should place it in. And somewhere i read "C:\Program Files\Autodesk\AutoCAD 2020\UserDataCache\Plotters". But i didnt have the needed permission for this folder. And then i found out that in my case its another folder.

 

to be succees in this you need to play with my pc3 + mpsetup.dwg untill you achieve what you want, do not challange it with other media sizes or your drawings.

Your rectangles are all smaller than the actual size of the respective paper format. Example: The A4 (Landscape) layout has a rectangle that is 277.1243mm x 168.8432mm. Does this have a reason?

yes margins

 

And if it still doesn't work, post your pc3 + dwg

i promise,  we will make it work by 'hook or by crook' 😀😁😂🤣

 

Must the paper format name be exactly as in the video? YES YES YES

Is it possible to Format the name like this? [Width]x[height]mm (Example: 2000x900mm)

Or maybe there is some problem because my AutoCAD is in german?

 

 

So only for a test sake, play with my rectangles make them a bit smaller and use my media sizes. i need you to say YES IT IS WORKING and then we will go from there. YES its working with the standard paper sizes (like A4, A2,....). It doesn't work with the other 4 layouts, but i didn't create any paper sizes because i don't know which margin width i should set it.

 

We're slowly getting there 💪

 

 

 

0 Likes
Message 26 of 94

Moshe-A
Mentor
Mentor

@thomas_schluesselberger 

 


@thomas_schluesselberger wrote:

Are you taking in consideration when you specifies a 2100x914 units rectangle to be plotted you need a bigger media size? make room for margin to leave - Ha 🤣

I don't want to have margin. I want it to crop perfectly to the rectangle.

Opa, this is the first time you say that?!  In exactly this wording it is the first time 😂

MPSETUP do not set (change) the default margin so a fix here is needed.

 

 

Are you using my PDF to DWG - MPS.pc3? did you add media size to it?

Yes i'm using your pc3. What do you mean by media size? Is that the paper format/size which i have to add before?

i asked that cause you said the system admin doesn't allow me to copy outside pc3 files?!

Yeah i know, at first i didnt knew where to put the pc3 and i googled which folder i should place it in. And somewhere i read "C:\Program Files\Autodesk\AutoCAD 2020\UserDataCache\Plotters". But i didnt have the needed permission for this folder. And then i found out that in my case its another folder.

 

to be succees in this you need to play with my pc3 + mpsetup.dwg untill you achieve what you want, do not challange it with other media sizes or your drawings.

Your rectangles are all smaller than the actual size of the respective paper format. Example: The A4 (Landscape) layout has a rectangle that is 277.1243mm x 168.8432mm. Does this have a reason?

yes margins

 

And if it still doesn't work, post your pc3 + dwg

i promise,  we will make it work by 'hook or by crook' 😀😁😂🤣

 

Must the paper format name be exactly as in the video? YES YES YES

Is it possible to Format the name like this? [Width]x[height]mm (Example: 2000x900mm)

Or maybe there is some problem because my AutoCAD is in german?

yes it's possible but the format must be pre fixed cause it is hardcodes (that part you did not understand and i said never mind but it is important to know, the name\format of the media size must be hard codes cause we do not have tools to read the pc3 file) so the media is assigned to layout by the name and if the exact name is not there it's error, the error you experienced.

 

So only for a test sake, play with my rectangles make them a bit smaller and use my media sizes. i need you to say YES IT IS WORKING and then we will go from there. YES its working with the standard paper sizes (like A4, A2,....). It doesn't work with the other 4 layouts, but i didn't create any paper sizes because i don't know which margin width i should set it.

i now at work and have no access to my computer at home so tonight i will make the necessary changes but as i now recall, maybe i did read the margins so give it another try

the default margins for the PDF is 13mm

 

We're slowly getting there 💪

 

 

 


 

0 Likes
Message 27 of 94

Moshe-A
Mentor
Mentor

@thomas_schluesselberger ,

 

i got back very late last night but did some checking and the result is that it work very good.

 

i hope you saw the video yesterday and you understand it's working 😀

to better understand why it is not working for you i want you to achieve what i have. so let's do it step by step cause if you are telling me that it's not working without telling me what have you changed, and not having an error messgae,  i can not recreate the issue.

 

i want you to run it on my MPSETUP activate layout 120x91.4 without changing media page name or size, use my DWG to PDF - MPS.pc3 and set User1 914x2000 mm media you can change a bit the rectangle but do not push it to it's limits,  leave at least 13mm margin) then run MPSETUP for the current layout and do REGEN

 

Does this work?

 

my version of AutoCAD is English i hope the Germam version does not influence here

the mpsetup program does read the margins and add it to the effective title block (or rectangle) for the match of media size. you can reduce the margine to a min of 1 mm but not zero (at this time)

but i do not recommend doing it cause first it's world standard and second when coming to add media size in pc3, beside the media length x width you have to set the margins and if you need to alot of medias, it is more work. so reconsider it and leave it 13 if possible.

 

about naming format of media size as is said you can change it (i need to know to what?) but again it's

require you more work.

 

Moshe

 

 

 

 

0 Likes
Message 28 of 94

thomas_schluesselberger
Advocate
Advocate

Hi, sorry for my late anwser.

 

i want you to run it on my MPSETUP activate layout 120x91.4 without changing media page name or size, use my DWG to PDF - MPS.pc3 and set User1 914x2000 mm media you can change a bit the rectangle but do not push it to it's limits,  leave at least 13mm margin) then run MPSETUP for the current layout and do REGEN

I did it like you said, but it doesnt get the 2000x914mm media. Only if i make the rectangle a bit smaller in height it changes to ISO A0(841.00 x 1189.00 mm).

If i dont change the rectangle the paper size gets really small (see picture 1) but in the Plot Settings it goes from "ARCH E (36.00 x 48.00 Zoll) to "Vorheriges Papierformat (914.00 x 1300.00 mm) (Vorheriges Papierformat is german for "previous papersize) . Thats really weird because when i measure the white area it is about 51x35 (see picture 2).

 

Picture 1:

thomas_schlu_0-1674458115212.png
Picture 2:
thomas_schlu_1-1674458403864.png

 

Maybe my paper size settings are wrong? I did the following presets for it:

Widht: 2000

Height: 914

Unit: Millimeter

Margins: top, bottom, left, right -> 13

Name: "User 1 (914.00 x 2000.00 mm)"

(i also tried it with the names  "User 1 (2000.00 x 914.00 mm)" and "User1 (2000.00 x 914.00 mm)" but they also doesnt work.

 

 

Does this work?

 

my version of AutoCAD is English i hope the Germam version does not influence here I think it only matters if you use direct commands in the LISP, like: "_rotate". I cant use this command, for me with the german version it is "drehen".

the mpsetup program does read the margins and add it to the effective title block (or rectangle) for the match of media size. you can reduce the margine to a min of 1 mm but not zero (at this time)

but i do not recommend doing it cause first it's world standard and second when coming to add media size in pc3, beside the media length x width you have to set the margins and if you need to alot of medias, it is more work. so reconsider it and leave it 13 if possible. 

I know its gonna be more work to create the papersizes but we need to have the margins set to 0, because we later import the PDF in other software.

 

about naming format of media size as is said you can change it (i need to know to what?) but again it's

require you more work.

I want it to be (example for 2000x900): "2000x900mm" or also "2000 x 900 mm" works. I just want it to look clean. 

I know that this means more work for me, but I will have it anyway, because when I create a paper format, the automatic name for me is "Benutzer 1 (XX x XX mm)" because I have the German version.

 

0 Likes
Message 29 of 94

Moshe-A
Mentor
Mentor

@thomas_schluesselberger  hi,

 

I worked on the app all this weekend and i made a massive changes. the major database of mpsetup is the page size \name list from the pc3 and i dicovered that it can be read from the layout or pagesetup objects (this is also the first time i am dealing with these objects, so it is a challange for me 😀) this as opposed to what i thought at first time i can not do but still there are no tools (functions) to write to pc3 file which require you to add page size manually.

it's still not finished.  i hope tonight it will be (or max another night) but i think now it will be solid. with the new version you will be able to create your own page size\ name freely.

 

So be patience my friend, we will beat this 🤣

 

Moshe

 

0 Likes
Message 30 of 94

thomas_schluesselberger
Advocate
Advocate

ok, thanks a lot for your time!

0 Likes
Message 31 of 94

Moshe-A
Mentor
Mentor

@thomas_schluesselberger  hi,

 

Attached the new version.

 

The mps_supp.lsp is not relevant anymore you can delete it. a new option is added to the prompt called 'printer' when you select it, a dialog box is open with all of your printer list to select from. the default is "DWG to PDF - MPS.pc3"

 

As i said earlier the pages size is now read from layout object. only pages of MM are taken that includes all your custom large pages ("ISO_full_bleed..."  and "ISO_expand..." of any kind are also eliminated). 

 

Maybe my paper size settings are wrong? I did the following presets for it:

Widht: 2000

Height: 914

 

yes this is wrong, the width should be the short edge (e.g 914)

now you can set zero (0) margins.

 

you use direct commands in the LISP, like: "_rotate". I cant use this command, for me with the german version it is "drehen".

 

no, i do not use autolisp (command) function at all.

 

the automatic name for me is "Benutzer 1 (XX x XX mm)" because I have the German version.

 

from MPSETUP point of view that does not matter anymore because it uses autocad core media names which you as a user can not see. you can name your pages size freely. 

 

Thomas,

again, start testing it on my mpsetup dwg bring it to work as i see it on my CAD and tell me it work?

set margins 0 for some pages to test and do not forget your request for restore. an RPSETUP command is also there 😀

 

enjoy

Moshe

 

 

 

 

 

 

 

0 Likes
Message 32 of 94

Moshe-A
Mentor
Mentor

@thomas_schluesselberger Good Morning,

 

Sorry forgot to compile it with dcl file last night, the attached is the complete one 😀

0 Likes
Message 33 of 94

thomas_schluesselberger
Advocate
Advocate

Hi!

 

It works most of the time with the standard paper sizes. I tried it with A4 and A3 and it doesn't always work.

Randomly it doesnt works and when this happens the unit displayed in the plot configuration switches from mm to inches (only sometimes so I can't tell why). 

 

What doesnt works is:

If I change the plot options (e.g. plot marks on), then these are reset after running MPSetup.

(maybe it is possible to set the plot settings via the lisp)

 

It still doesn't work with the paper formats I created myself.

The LISP cant find the page size: Can not find a suitable page size for "A4 (Landscape)" layout.
Maybe I'm still creating the paper sizes wrong. The paper formats I have created myself are saved in the PC3 configuration under "Custom paper sizes" -> is that correct?

thomas_schlu_0-1674556051268.png

 

 

0 Likes
Message 34 of 94

Moshe-A
Mentor
Mentor

@thomas_schluesselberger ,

 


@thomas_schluesselberger wrote:

Hi!

 

It works most of the time with the standard paper sizes. I tried it with A4 and A3 and it doesn't always work.

Can you make a video so i can see?

Randomly it doesnt works and when this happens the unit displayed in the plot configuration switches from mm to inches (only sometimes so I can't tell why). 

that's weird cause i am setting it to mm.

 

What doesnt works is:

If I change the plot options (e.g. plot marks on), then these are reset after running MPSetup.

what's that?

(maybe it is possible to set the plot settings via the lisp)

yes there is and i am settings the required settings to make it work (e.g the printer, page size, units, scale)

 

It still doesn't work with the paper formats I created myself.

The LISP cant find the page size: Can not find a suitable page size for "A4 (Landscape)" layout.

if this my mspsetup.dwg? post only your pc3 file.
Maybe I'm still creating the paper sizes wrong. The paper formats I have created myself are saved in the PC3 configuration under "Custom paper sizes" -> is that correct?

yes, it looks ok

 

thomas_schlu_0-1674556051268.png

 

 


i do not know if the Germen version has effect on this (do not have that version) but if you have an english version, can you install? to avoid collision, install a lower or higher version from your current.

 

Moshe

0 Likes
Message 35 of 94

thomas_schluesselberger
Advocate
Advocate

Hello!

 

I have now tested it again and noticed that the problem with the change over to inches only occurs if I want to use larger paper sizes like 2000x900mm. (see Video "Inch-Problem")


It works for A4. However, I also noticed that it does not work if the A4 frame is too far from the 0 point (see video "xxx").

 

 


What doesnt works is:

If I change the plot options (e.g. plot marks on), then these are reset after running MPSetup.

what's that?     "Plot stamp on" is what i meant. (the setting so that the date and the save location are displayed on the bottom left of the plan)

                           The plot options I select here get reset:

                           thomas_schlu_0-1674563528045.png

 

It still doesn't work with the paper formats I created myself.

The LISP cant find the page size: Can not find a suitable page size for "A4 (Landscape)" layout.

if this my mspsetup.dwg? post only your pc3 file.          See Attachments
Maybe I'm still creating the paper sizes wrong. The paper formats I have created myself are saved in the PC3 configuration under "Custom paper sizes" -> is that correct?

yes, it looks ok

 

i do not know if the Germen version has effect on this (do not have that version) but if you have an english version, can you install? to avoid collision, install a lower or higher version from your current.

Unfortunately I can't change my version, but until now every LISP (also from people who had english versions) worked.


 

0 Likes
Message 36 of 94

Moshe-A
Mentor
Mentor

@thomas_schluesselberger ,

 

checked it and the only thing i see when you move the rectangle to -X coords it doesn't work - will fix it tonight 

the pc3 you post does not contain any custom page size.

 

be careful when specifying plot stamp with zero margins cause the plot stamp is placed in the margins.

 

 

0 Likes
Message 37 of 94

thomas_schluesselberger
Advocate
Advocate

@Moshe-A  schrieb:

@thomas_schluesselberger ,

 

checked it and the only thing i see when you move the rectangle to -X coords it doesn't work - will fix it tonight OK!

 

the pc3 you post does not contain any custom page size.

Weird, i just uploaded the pc3 where the paper sizes are included (see in the photo):

thomas_schlu_1-1674573901669.png
Maybe you can send me a picture of how it looks on your pc3.
Or maybe the paper formats are only saved locally?
be careful when specifying plot stamp with zero margins cause the plot stamp is placed in the margins.
Has always worked without problems, I configure it so that it has a gap on the left and bottom.
But thanks for the hint!

 


I have attached the exact file from which I took the photo above. 

 

 

0 Likes
Message 38 of 94

Moshe-A
Mentor
Mentor

@thomas_schluesselberger ,

 

fixed program is attached, very close to final 😀

 

Moshe

 

 

 

 

 

 

0 Likes
Message 39 of 94

thomas_schluesselberger
Advocate
Advocate

Nice!

 

Works really good now. But still my custom paper sizes cannot be found.

Any Ideas of how i can fix this? Do the custom paper sizes work for you?

 

I just found out that I can only send you my custom paper sizes if you also get the PMP file.

That's why my PC3 and my PMP file are attached. So you need to link the PMP to the PC3 and then you should be able to see my custom paper sizes.

Maybe you can test if it works for you with my paper sizes.

(I made sizes for 2000x900 and 1000x900)

0 Likes
Message 40 of 94

Moshe-A
Mentor
Mentor

@thomas_schluesselberger ,

 

the pc3 you post does not contain any custom page size.

Weird, i just uploaded the pc3 where the paper sizes are included (see in the photo):

 

Yes this is totally weird. at office under R2022 i did not see any custom page size. at home under R2018 i did see them.

 

Works really good now. But still my custom paper sizes cannot be found.

Any Ideas of how i can fix this? Do the custom paper sizes work for you?

 

Yes on my AutoCAD it works well and i have a brilliant  idea: the problem is page size naming in German so here is a lisp command called TEST for you to run on your machine. it prints to AutoCAD text window all the pages size from 

"DWG to PDF - MPS.pc3". copy and paste it to notepad and save it as test.lsp and appload it into autocad and run TEST command. 

 

copy and paste the output to notepad and at each end of line add a translation to English so i can recognize them.  you can remove those that are not MM. save it as text file and post it back (this i hope will solve this problem)

 

Moshe

 

(defun c:test (/ adoc AcDbLayout)
 (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
 (setq AcDbLayout (vla-item (vla-get-layouts adoc) (getvar "ctab"))) 

 (vla-put-configName AcDbLayout "DWG to PDF - MPS.pc3")
  
 (vl-every
  '(lambda (media)
    (terpri) 
    (prin1 media)
  ); lambda
  (vlax-safearray->list (vlax-variant-value (vla-GetCanonicalMediaNames AcDbLayout)))
 ); mapcar

 (vlax-release-object AcDbLayout)
 (vlax-release-object adoc)
  
 (princ) 
) 

 

 

 

0 Likes