cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Macro to export CGM

LaurentPujalet
1-Newbie

Macro to export CGM

Hello everyone.

I am very new to IsoDraw, using v7.3, and I have a small issue.

I want to convert .CGM file to its clear text encoding. I know my input file is encoded in binary and I want to use a command line to convert it to clear text encoding. There are a few things I don't understand :

- What should be the command like ? For now I've been trying to change many subtleties but nothing seems to work.

I always start with this : [path_to_isodraw.exe]\IsoDraw73.exe -s"path_to_source_file" -d"path_to_destination_file" . Then I try to use a simple macro with this only command "Export "path_to_cgm" "CGM". I checked in the preference file for my specific parameters and it seems ok. This macro is saved in my C:\User\myname\AppData\Roaming\ptc\Isodraw\Macro so I add this to my command line, giving this :

[path_to_isodraw.exe]\IsoDraw73.exe -s"path_to_source_file.cgm" -d"path_to_destination_file.cgm" -m"C:\C:\User\myname\AppData\Roaming\ptc\Isodraw\Macro\convertCGM.ism".


Now others questions I have are the following :

- There is a destination file in the command line and another one in the export line of the macro. Doesn't this create a conflict ? To make things simpler, I use the same path but.. still.

- I know there's a -f10 command line option that allows to convert in CGM. How does it precisely work ? Does it conflicts with the export command of the macro ?

- This command worked once on a test file. I tried it again on another file and I could'nt make it work again. Am I missing something ?

- Imagine I want to specify my Export "CGM" command. Let's say one to convert into binary and the other to convert into clear text. Is this possible ? I tried to do some changes in the preference file (changing CGM to CGMBinary and adding CGMText) but this doesn't seem to work. I guess we can't add new commands ? Are we supposed to change the parameters each time ?


That's it for now, thank you in advance for any help. I've looked around the forums, guides and help but couldn't find anything useful, so any help is appreciated

1 ACCEPTED SOLUTION

Accepted Solutions

I apologize for not being more thorough the first time. I just knew that the macro name was used. I've gone through and tested on mine. Here is the syntax to use.

[Install location]/IsoDraw73.exe [Path to file] -macro [Macro name]

I'm guessing you might have looked at older documentation as I have a vague recollection that the syntax changed a few versions back.

Also note that you may need to add the following line to your macro to close IsoDraw when the macro is done. Otherwise it may leave a running instance.

     Quit Confirm_Yes

View solution in original post

20 REPLIES 20

I think you might be making this more complex than needed though I'll answer some of your other questions as well.

First, open IsoDraw, and assuming you're on a more current release we're on 7.3), you should find 'Batch process...' under 'File' in the menu. You can then select a folder of files you want to convert. Pick a destination (do not do the same folder), and the options to export. Since you're just switching the export basically you shouldn't need a macro.

In regards to the some of the questions in your post, the settings for an export are stored in the preference file as it appears you are aware. Each time you reopen a file it goes back to these defaults. Once a file is created it does NOT get any updates from the preference file. It is stored in that file and only modifiable via the UI or via macro. So, when running a macro, if you simply do an export it will use those default settings. There are commands to automatically change these prior to export. I recommend this in case you have a needed export format and someone plays with the settings for the file. And yes, you would need to set this between each export.

As for the conflict, I'm not sure. Never tried. On the other hand, are you giving explicit paths? My guess if they are the same path is that the file opens, runs the macro creating the file (no lock), and then your destination file is created overwriting the previously exported file.

The thing is that I need to call IsoDraw from my java code. So I'm testing it from a console and it seems that command lines aren't much customizable. I saw in the documentation that starting from 7.1, this is the generic command : "[path]\IsoDraw7.exe" -ext <plugin name> -s<path of source files>
-d<path of destination files> -f## -c<scale value> -m<name of the macro>

As I need to execute a command to export in the right CGM format, what would be the command to just make an export ? Since I can manually change the preference file, I don't need to do anything special in the command, just call the macro that export to CGM. At least, that's how I understand it.

I am always giving the whole path to my files (I am not using "..\..\myfile" but always "D:\path\to\myfile").

Ah. Now I understand the direction. I didn't actually test the below but it should work.

Macro CGM_Export

     #Various cgm export settings. Listed only a few that might help.

          #Sets export profile for cgm.

               app.cgm.profile = $CGM_Profile.ATA_GREXCHANGE_2_9

          #Sets encoding to text.

               app.cgm.profile = 2

          #CGM version

               app.cgm.version = 1 

   

#Exports cgm to the same directory as the source file.

     Export StripExt(ActiveDoc.Path) + ".cgm" CGM

End Macro

Oh thank you a lot, that's the kind of thing I suspected I'm gonna test this

Do you know if there is any documentation anywhere that lists all the settings for export ?

I can see in the preference file that "Export CGM" is followed by a list of values but I don't know which one it matches to. Do you also have any documentation regarding "app.cgm.xyz" ? Which exist, what do they mean, etc. ?

Thanks again !

EDIT : Ok nevermind, I found the "Macro reference language" document. For those interested, you can find it here : http://support.ptc.com/WCMS/files/141324/en/isod-mlref_en.pdf

I still need to understand how to make it work though 😕

Macros actually have their own entire section in the help section. Depending on your version you may see a section under 'Help', but newer versions you go to Help -> Help Topics and you'll see the section there.

I still don't understand why I don't have any result file.

This is what I'm executing : [path_to_isodraw7.3]IsoDraw73.exe -s"D:\input\myfile.cgm" -d"D:\output\output.cgm" -m"C:\Users\myname\AppData\Roaming\ptc\Isodraw\Macros\exportCGM.ism"

And the macro exportCGM.ism is this :

BEGIN Macro exportCGM

app.cgm.profile = $CGM_PROFILE.ISO_8632_1999

app.cgm.encoding = 2

app.cgm.xyz = 4

Export "D:\output\output.cgm" "CGM"

END Macro

Do you have any idea why it doesn't produce any result ? The macro seems ok since isodraw macros debugging doesn't show any error... I'm lost, I feel like I tried everything

Is the word 'BEGIN' actually in your macro? It shouldn't be.

Try opening a file and manually running the macro to see if it works.

Also, the call I believe should be to the macro name, not the file. All macros in the 'Macros' folder get loaded into memory. You then reference them through the name. It is easily possible for a single file to contain multiple macros so calling it at that level does not work.

In regards to errors, I have a vague recollection that calling IsoDraw via this method suppresses errors since it has traditionally been used in batches or through automation where an error pop-up would cause a potential lock.

Yes, I'm sorry, I wrote it from memory but there isn't "BEGIN". I tried, as you said, to manually run the macro from isodraw and it worked perfectly.

I also tried to run the command with different path to the macro, or without path, or without ".ism" but nothing worked.

Thank you again for your help, I'm sure we'll manage to make things work !

Try the following:

[path_to_isodraw7.3]IsoDraw73.exe -s"D:\input\myfile.cgm" -d"D:\output\output.cgm" -m "exportCGM"

You can do this from a CMD window to see if any errors are returned from an invalid call.

I tried, without success. I also tried every possible variation -m or -macro, with or without space before the quote. I tried with full path to the macro, with extension or without. I tried to place the macro in different folders. Nothing worked.

And I don't have any errors returned. When I try this macro manually from isodraw after opening a .CGM file, it works perfectly.

Each time, the command opens Isodraw and doesn't do anything. It feels like it either doesn't understand I'm sending parameters for a command, or the macro isn't understood, or I'm not waiting long enough for Isodraw to do something (but I doubt it since it should be quite fast to convert).

I'm running out of ideas

I apologize for not being more thorough the first time. I just knew that the macro name was used. I've gone through and tested on mine. Here is the syntax to use.

[Install location]/IsoDraw73.exe [Path to file] -macro [Macro name]

I'm guessing you might have looked at older documentation as I have a vague recollection that the syntax changed a few versions back.

Also note that you may need to add the following line to your macro to close IsoDraw when the macro is done. Otherwise it may leave a running instance.

     Quit Confirm_Yes

Thanks a ton, it works !

I'm glad to know I had reasons to believe there might be a conflict between the macro and the -s or -d parameters, actually just one path to the file is necessary.

Do you know if there is a way to have the same output name as my input ? I am currently writing into "output.cgm" but I'd like to replace my input file with my new one, I need the correct name though...

For the file name itself without extension use the following.

     StripExt(ActiveDoc.Name)

File name with path is as follows.

     StripExt(ActiveDoc.Path)

Using the last one as an example, you could do something like the following.

     Define NewFileName as string

     NewFileName = StripExt(ActiveDoc.Path) + ".cgm"

I should've been more acurate. I tried this already and it makes IsoDraw pop the "Save as" window up and saves as ".cgm", without a name.

I think it also saved as "Untitled - 1.cgm" when I tried with two variables (path and name, I wrote path myself).

Can you post your code?

This is my macro :

Macro exportCGM

  app.cgm.profile = $CGM_Profile.ISO_8632_1999

  app.cgm.encoding = 2

  app.cgm.vdcType = 2

  app.cgm.version = 4

  DEFINE path as String

  path = StripExt(ActiveDoc.Path) + ".cgm"

  Export path "CGM"

  Quit Confirm_Yes

End Macro

This opens isodraw, opens my file, start to export to CGM but opens "Save as" window.

I ran this by opening a file in IsoDraw. I then started the macro. It ran and closed IsoDraw with no issue. I also confirmed the cgm exported to the same directory as the source idr.

Where are the files being called from? Are they stored locally?

Yeah, if I open a .IDR and manually starts the macro, it's all good and works fine.

If I open a .CGM and runs the macro, it opens the "save as" windows.

This two cases happen after I already have IsoDraw open. What I want is to call this macro from a windows console. This means IsoDraw won't be opened in the first place (I don't know if it changes much).

Also, I don't have .IDR files, only .CGM.

Ah. I guess I forgot about some of that. The problem is that you're exporting a CGM to replace your currently open file. That's why I didn't get the error. I think you're going to need to export to a different location or give the file a different name. I'm guessing the latter might be easiest. If you simply prefix/append anything you should be able to remove it via your java call.

All right it's all good now. We added a "Close" call just before the Quit command and we changed the name of the exported file.

Thank you again for your help, it's very appreciated !

Top Tags