DXF/PDF recording via macro

Hello

I'm currently trying to take the code of a macro I found (http://www.lynkoa.com/forum/documents-commerciaux/ma-macro-pdf-dxf-quoi-en-dire). It was running on SW2013 (I'm on SW2015). I specify that I don't know anything about VBA, so I try to transpose my knowledge into other languages to solve the problems.

I first got the error Project or library not found. I copied the code from the original file and pasted it back into a new macro and it seems that it solved the problem.

Now, it seems that my macro is no longer running as it should (well, it is running but not as I would like). I run it and it tells me that it couldn't save files in DXF.

The avenues I am considering:

-Macro does not detect that SW2015 is open

-The macro does not find the MEP currently open (but normally, it should show me an error)

 

PS: I tried to add a small piece of code to check that the destination folder exists. However, it didn't launch either, I put it in the comments and I took the original code.

Thank you in advance for your help and I'm starting to learn VBA on my own.

 

 


macro1.swp

Hello

Is there an error message?

Is it possible to see the code in a text file? (No SolidWorks on hand yet).

Hello

Hey@PL I've quickly copied the macro in txt format;)

I know too little  about it and its the ultracomplex area am a little lost @_ @


macro.txt
1 Like

Thank you@Centor

@nuemishra: you added this line:

  'The following lines don't seem to work, I put the base code back on top. The code being verified, it must be from the main error

 

 

Yes, I was the one who added this line. But I know why it doesn't work: I had forgotten to add Dim fs As Scripting.FileSystemObject and reference Microsoft scripting runtime. I still have to correct my Address (which currently recovers path\nom_fichier.slddraw and not just path\), I have the solution, it's not perfect but it works. I'll improve that if it's validated.

 

The main problem (the one that led me to post) is that I can run the program in step-by-step mode of debugging but not by running the macro. In debug mode, everything seems to work (except maybe saving the DXF, it crashes the debug but it creates the files well).

Regarding the debug crash on the DXF record, when I get to the level of the Dir = swModel.SaveAs4(CompleteDocName, 0, 0, 0, 0 statement ), the debug mills and then stops. After checking, it seems that it saves the three sheets of my test MEP (it seems that the function saves the three sheets at once). When I restart, it asks me if I want to overwrite the existing file (and it asks me for each page)

I put back to my corrected macro in .txt

EDIT: Update of the macro1.txt

 


macro1.txt

I would be tempted to say that SolidWorks does not have the time to create its DWG when it is asked to make another one. We should try to include pauses in the code:

Two examples of a break:

1)

Application.Wait Time + TimeSerial(0, 0, 5)' pause of 5 seconds

2)

Declare Sub Sleep Lib "kernel32" aka "Sleep" (ByVal dwMilliseconds As Long)

 

Sleep 2000 ' 2 second pause

Damn, I must be too bad again.

I'm getting two different errors and I can't seem to solve them.

For the first pause method, it tells me: "Runtime error '438': Property or method not handled by this object"

For the second method, it tells me: "Compilation error: The code contained in this project must be updated to be able to be used on 64bit systems. Check and update the Declare statements, then mark them with a PtrSafe attribute"

For the first method, I first tried to test directly in the main sub (just below AffectVar01), for the second, I put the Declare below Public RepUtil (I also tried to put it in the main sub out of desperation... Who knows, maybe I didn't understand anything about VBA)

 

EDIT:

I found a patch. A sub I found while searching on google waiting in a loop. Unfortunately, this does not solve the problem. When I run normally, it keeps telling me that it doesn't save any DXF (by the way, it doesn't save PDFs either but as you said, it must be because the macro goes too fast for the system). 

FINALLY!! I came back because a colleague suggested that I run the macro with huge breaks and it finally worked!  After a few tests, it worked with 100 in each tempo, I managed to make it work once with 20 in the first and 5 in the second. I will continue the tests to see the minimum waiting time.

A big thank you to you!

 

EDIT²:Well, I spoke a little fast. When I run it from the macro editor, it works, when I do Tools=>Macro=>Run, it doesn't work anymore. As I have to link this to Smart Properties, it may not be a problem, I'll see if via Smart Properties, it works (in any case, Tools=>Macro=>Run doesn't go through the macro since I immediately get the message that there is nothing saved and this, despite the 3 times 20 seconds of tempo)

 

Finally, even if SW refuses to let me launch the macro by hand, it works without any problems via Smart Properties.


macro1.txt
1 Like

So if I understood correctly, the macro works as you wanted, with Smart Properties, and step by step, but not by launching it through the macro menu?

That's right. When I launch it via the run menu in Tools = > Macro, it doesn't work. But since I don't intend to use it like that, it's not a big deal. 

1 Like