Macro PDF recording with property recovery?

Hi all

I'm making a macro that allows me to save a drawing as a PDF in a specific folder. So far everything works properly (what a time saver).

But I'd like to add a change to it:

I would like the name of the PDF file to match the "reference" property, I have tried different solutions but I can't do it.

Does anyone have a solution???

Attached is my macro.

Thank you in advance.

 


macro_pdf.swp

Hello

Could you post the code of your macro in a TXT file please?

There you go...


macro1.txt
1 Like

Slt

Here's my macro in TXT format.

Hoping to find a solution thank you.

 

 


macro_pdf.txt
1 Like

As stated in the question:

http://www.lynkoa.com/forum/3d/macro-d-enregistrement-en-pdf

You have to go to 3D to get the property back.

Please test the macro in PJ.


macro_pdf_reference.txt
1 Like

I had already seen this question and tried several times but it didn't work.

When I run the macro you gave me its blocked at this level:

Set swView = swDraw.GetFirstView

Thank you


bloquage_macro.jpg

Is it a plan that is open in SolidWorks? What is the error message?

Yes, it's a plan that is open.

Runtime Error 91

Object variable or block variable Not set

 


bloquage_macro_2.jpg
1 Like

Good evening

The problem is on the line Set swDraw = swModel.

Since swModel doesn't exist, it's Set swDraw = Part

On the other hand, if the code is complete, it would be nice to remove the variable declarations that are not used and declare the ones that are not (e.g. Dim swDraw As SldWorks.DrawingDoc)

 

1 Like

Try with the attached file.

Indeed, as @liryc recommends if your code is limited to this macro, I cleaned up the variables too.

 


macro_pdf_reference.txt

Hello

Following the test with the .PL macro, there are no more execution errors but nothing happens.

We can see that his work but no PDF document is created.

This simple macro is giving me a lot of trouble.

Thank you.

On closer inspection, these lines are weird to me:

swPath = Left(swPathName, InStrRev(swPathName, "PLANS_PDF_SYLOB", , 1))
swPath = swPath & "T:\PLANS_PDF_SYLOB\"

For you too?

Hello

I confirm .PL's remark.

Considering how it's coded, it's a path like xxxT:\PLANS_PDF_SYLOB\ so obviously not much happens.

Put a debug.print swPath and see how it's formatted.

Also looking more closely I have the impression that the code is very complicated for something very simple.

 

Hello

After many tries without results, I abandon my macro which is quite simple.

Macro ==> Save as PDF in a fixed specific file with file name = the Part Reference property.

Thank you to everyone who tried to help me.

 

It's a shame to stay on a failure, you were really close to the goal.

You looked at the lead I gave you in my last message and that liryc confirmed too.

Want to post the last code you have and I'll look when I have time?

It's a shame to stay on a failure, you were really close to the goal.

You looked at the lead I gave you in my last message and that liryc confirmed too.

Want to post the last code you have and I'll look when I have time?

Hello

Looking for a macro of this type I admit my disappointment to see that this one is not finished.

But thanks to you I managed to finalize it.

The flaw I found is that the name of the jam to be interrogated was "" !!

referenc = swRefDoc.GetCustomInfoValue("", "referenc")

After modification:

cfgName = swRefDoc.GetActiveConfiguration.Name
referenc = swRefDoc.GetCustomInfoValue(cfgName, "referenc")

I also added a control function if the file is already open to be sure to save something.

I hope I can be useful to others.


slddrw_vers_pdf_avec_proprietes.txt
5 Likes