Sub String question

Started by admsteck, February 02, 2010, 07:50:22 AM

Previous topic - Next topic

admsteck

Does Polyworks have any macro command similar to the instr, and mid commands in vb?  I inspect mainly sheet metal parts and name all my cad files in the format "part# tx.x.iges" where part# is the part number and tx.x is the thickness of the part.  So a 1mm thick part would be t1.0.  I would like to be able to extract the thickness from the file name and use it to set the virtual surface property of the cad in Polyworks.

Admin

Is your problem now setting the property or extracting the value from your name?

admsteck

Extracting the value from the name of the file.

Admin

My first thought was to use the TREEVIEW REFERENCE GET NAME and then write the name to a text document.  Then I'm not sure exactly how to read only the certain section of the txt line.

admsteck

I have no problems getting the name of the file.  I am using the macro to import the CAD from the beginning and Polyworks has string functions that easily remove the path and file extension.  I had thought about using an external vb script but then I have no idea how the get the result of the vb functions back into the Polyworks macro.

Admin

Are you aware that PolyWorks can read and write lines of a text file? Take a look at the following functions:

QuoteDATA_FILE CREATE("$_pwk_files_path\user-data\example.txt", "ascii", "yes")
DATA_FILE APPEND LINE ("$_pwk_files_path\user-data\example.txt", $variable_1)

Then when you need it
QuoteDATA_FILE READ LINE_FIELD ("$_pwk_files_path\user-data\example.txt", 1, 1, variable_1)

I once used this functionaily to store information between multiple macros and even different days working on the workspace.  I found it easier than the global variable which I had a little trouble with.

Just check out the DATA FILE section of the "HTML Command Reference" from the Help menu of the Macro Script Editor.

admsteck

Thanks!  I was looking for something like that.  I should be able to export the file name to a text file, execute an external vb script to parse the file to get the part thickness, and then read the file back in to set the thickness on the reference model.  Not exactly the most straight forward approach, but it should work.

Admin

It's all about the work around  ;)

admsteck

Using your suggestion I have a working solution now.  :)  Thanks again for the help. 

ONCommand

Or you might use the SplitString()Command of the ONCommand Plugin...

Unfortunately only availible for the 32bit version at the moment - but I look forward...

As addition to Admin's soulution,(which works very well!!) I would recommend to build up a small Ram-Drive(1-10MB) for such cases as Volume Z: .
You find a Description on the www.ONCommand.de Website at Tips and Tricks...

Regards, Oliver

P.S. I do not find any introduction topic/thread, so I hope, I am welcome anyway:-)