Jump to content
AEChadwick

How can I Round Numbers to fewer decimal places in “Export Script” results

Recommended Posts

I have been using “Export Script” to quickly create instructions for a series of simple polygons (moulding profiles).

 

Does anyone know any way to decrease the dimensions from 15-decimal-point accuracy to maybe 2 or 3 points?

 

Even the simplest shape results in charming-but-ludicrous numbers like...

LineTo(2.79882798298577" , 0.000000000000004");

Honestly, rounded numbers would be fine—besides, i swear that Y point is really at 0...

LineTo(2.8" , 0");

I usually edit the numbers manually, but my next project involves about 500 polygons and i would love to streamline the process.

 

I have looked through vectorworks preferences and document preferences, and I have tried different Page Unit settings.

 

I cannot determine where export script accuracy is derived.

 

If there is no way inside Vectorworks, I will simply export everything to a text file and use a separate shell script to just round every number.

 

 

Share this post


Link to post

It is not going to happen in the Export Script. No way I know of to change that.

 

Probably the best option would be to run the exported text file though another script (possibly outside of VW) that would do the rounding/truncation for you.

 

Pythonscript inside of VW would probably be a reasonable thing to do also, but I am not strong enough in Python to know if this can be done with basic Python or if if could be done really easily using a python library file of some kind. Hopefully one of our Python guru's will chime in. 

 

Any ideas @JBenghiat, @bcd, @twk, @The Hamma, @tbexon?

Share this post


Link to post

Mr Stanford, I rely on you for the cold truth. I always appreciate your responses.

 

(I kind of figured this would end with me writing a script to process the results of the export’d script.)

Share this post


Link to post

Maybe tell us more about what you are actually trying to accomplish and we might be able to come up with a different solution that would better meet your needs.

 

I was just having a conversation with @michaelk on Saturday and he was having a problem that he traced back to using Export Script without being careful enough with what it does. He created a bunch of scripts from Export Script and found they worked great in single story construction but always put the objects on the "ground floor" in multi-story. Turns out that Export Script set the Z-value to zero after EVERY object. So while it gives you a good starting point sometimes, you really need to be careful with which parts of the export you actually use.

Share this post


Link to post

I appreciate any insight; there’s not much more to specify, but i'm happy to explain and i respect you taking the time.

 

I have profiles of every piece if moulding from several common catalogs; i keep them as a symbol library to add into drawings.

 

My Production Designers often change their minds from moment to moment, which leads to searching, copying, pasting, etc.

 

I figure i could speed the process up with a PIO Point Object to just change between any molding with a couple clicks—turn every profile into a series of commands, and simply case-switch through them based on catalog and number.

 

(I think a plugin that draws the object is more flexible and more fun than something that simply automatically calls up the existing symbols. it introduces some fun ability to customize the piece on the fly.)

 

Since I already have the profiles, it's quick work to just export—with some cleaning up.

 

(I don't trust any script as a straight export, i just use the export as a jumping off point.)

 

For example...

NameObject('P143 Section');
ClosePoly;
BeginPoly;
  MoveTo(0",-4.687499999999996");
  MoveTo(0",-2.797591863254474");
  MoveTo(2.79882798298577",0.000000000000004");
  MoveTo(4.67684947143633",0.000000000000001");
  LineTo(4.67684947143633",-0.737820846534148");
  ArcTo(0.704415179296854",-0.715267855549387",3.904543571406666");
  LineTo(0.750400322129494",-4.687499999999996");
EndPoly;
SetVertexVisibility(LNewObj,0,false);
SetVertexVisibility(LNewObj,1,false);
SetVertexVisibility(LNewObj,2,false);

Becomes part of a procedure, like...

ClosePoly;
BeginPoly;
  MoveTo(FromX+0",FromY-4.687");
  MoveTo(FromX+0",FromY-2.8");
  MoveTo(FromX+2.8",FromY+0");
  MoveTo(FromX+4.68",FromY+0");
  LineTo(FromX+4.68",FromY-0.738");
  ArcTo(FromX+0.70",FromY-0.72",3.90");
  LineTo(FromX+0.75",FromY-4.68");
EndPoly;
SetVertexVisibility(LNewObj,0,false);
SetVertexVisibility(LNewObj,1,false);
SetVertexVisibility(LNewObj,2,false);

i've done a similar thing in a couple PIO—using the result of an export to draw a decorative feature as part of a bigger process.

 

It works great, and honestly the clean-up process is kind of fun—finding all the patterns and recurring numbers and shapes. but... i think after 300 profiles i might get fatigued...

 

Anyway, roll that all through your head. I appreciate all your contributions. (And I love when JBenghiat enters a discussion, i hope he throws something in here too!)

Share this post


Link to post

Pat's being kind.  My oversight caused even bigger problems than that!

 

I have the same experience as you cleaning up and formatting snippets of script copied from an export.  I caught the problem while finishing the clean up after the tool was "done and working".

 

Let's hope Josh stops by and talks slow enough that the rest of us can understand it :-).

 

btw the plug in you describe already exists.  I've been using it and it's really good.

 

Share this post


Link to post
1 minute ago, michaelk said:

 

btw the plug in you describe already exists.  I've been using it and it's really good.

 

 

i've seen that plugin! it's lovely work.

 

but. it doesn’t use the Paramount and/or Fox catalogs.

 

and. it doesn't draw to my particular style (i love writing PIO to do my specific drawing for me...)

 

also. my mill doesn't need 3D anything, they just want to see the profiles and read the numbers.  : )

Share this post


Link to post

You can't control the numbers that come out of the exported script. With scripts, you actually get the raw data that VW stores, so it won't be affected by units settings.

 

You could potentially write a script that queries objects and writes each vertex coordinate and type to a file — in that case you would be able to control the number format.

 

Otherwise, a text editor that can do grep searches, like BBEdit is your friend.

Share this post


Link to post
Posted (edited)
27 minutes ago, JBenghiat said:

You could potentially write a script that queries objects and writes each vertex coordinate and type to a file — in that case you would be able to control the number format.

 

oh i like this idea. thank you!

Edited by AEChadwick

Share this post


Link to post
19 hours ago, JBenghiat said:

You could potentially write a script that queries objects and writes each vertex coordinate and type to a file — in that case you would be able to control the number format.

 

This is what I would advise also.

Share this post


Link to post

It is fun to experience the success of drawing something via a script (I've gotten caught up in that aspect many a time). From a practical point your symbol library already exists and it is a great launching point for your plugin. I assume that you already have these 300 plus profiles drawn as a polyline, each in their own symbol, and pre-indexed by name from those catalogues in a Vectorwork's file. This makes an excellent a library resource file that your plugin can search through based upon an index name typed into the OIP, or emulate the technique used in the wide flange steel beam tool (long lists of predetermined sizes sorted by applicable standards organization, add an option to branch to a script for non-standard entries). It is also easy to add non-standard variations to the library file by simply duplicating a similar existing symbol making the edit and giving it a unique name to add to your list.

The bulk of your profiles remain in the library file stored on your drive while the plugin only imports the profiles that are utilized into your project file. At this point if these symbols cluttering your resource palette you can convert the imported instance to a group and ungroup leaving only the outline that was originally in the symbol. follow it by deleting the named symbol from the symbol library. Alternatively your script can create a folder (if it doesn't already exist) to contain these symbol definitions then repeated use of a particular profile will not significantly add to the project's file size.

 

Ok, I had nothing better to do tonight to distract myself from thinking about dental surgery tomorrow.

  • Like 1

Share this post


Link to post
12 hours ago, LarryO said:

excellent a library resource

 

hey Mr O! thanks for joining in. Pick-and-place is a fine solution, but procedural generation of each profile will lend itself to several ideas i have for on-the-fly customization.

 

I’ll check back in once i have developed something. (Hope your surgery went well! keep ice on that jaw!)

 

—AE

Share this post


Link to post

In this Mouldings plugins package, there is the possibility to create your own profiles library (to add in the existing libraries menu / dialog).

 

image.thumb.png.503b8fd462ade3f8b36ed30c13d7085b.png

 

Libraries are used by all the plugins of the package:

  • Moulding on 2D Path
  • Moulding on 3D Path
  • Frame (Rectangular)
  • Siding
  • Corner
  • Frames (Array)

The tool to create profiles is called Save Profile to File cpf, it requires you select the polyline (or polygon), click on the insertion point (used by the plugins), then save to a .cpf file that is actually a text file.

The file produced appears like this (a crown profile, in this case):

 

CORNICI_Profile_File
2
1
moveTo(0, -5.45330085889904);
lineTo(0, -4.53856277202472);
lineTo(-0.441941738241592, -4.09662103378312);
lineTo(-0.618718433538227, -4.09662103378312);
lineTo(-4.09662103378311, -0.618718433538241);
lineTo(-4.09662103378313, -0.441941738241589);
lineTo(-4.53856277202473, 0);
lineTo(-5.15330085889915, 2.1316282072803e-14);
lineTo(-5.15330085889913, -0.79999999999999);
ArcTo(-3.8483168972336, -0.998963062315383, 2.28525471487043);
lineTo(-3.36867413939314, -2.22880543645175);
ArcTo(-2.82778252416896, -3.61569477720361, 2.98477656112482);
lineTo(-1.39454361649037, -4.01800313708096);
lineTo(-1.3945436164904, -4.35175753780095);
ArcTo(-0.500000000000035, -4.53930776780022, 1.12549345439392);
lineTo(-0.500000000000036, -5.45330085889907);

 

Share this post


Link to post

Totally. That's similar to how i have been creating the instruction sets to build profiles—exports from my own library of polylines of the Paramount and Fox catalogs. (Aren't those numbers something??? "-0.500000000000036" and "-0.500000000000035", like, really...?)

 

That plug-in is excellent, it's another lovely example of the idea. It doesn't allow the illustrative customization that i want, but i appreciate seeing different versions.

 

Share this post


Link to post
1 hour ago, AEChadwick said:

(Aren't those numbers something??? "-0.500000000000036" and "-0.500000000000035", like, really...?)

 

It's a combination of how computers store float values in memory and the fact that internally VW stores all dimensions in mm and converts the value to the user-set units for display. VS shows you the raw data, in the current units system.

  • Like 2

Share this post


Link to post

Inspired by this post, I have added the full Paramount Wood Moulding catalog to my Mouldings Plugin.

It taken just one day to convert all the downloaded dwg files to the proprietary cpf files (with the above mentioned tool Save Profile to File cpf).

I did not found downloadable dwg archives for the Fox catalog, @AEChadwick could you give me a link?

 

833540242_Schermata2020-09-09alle16_21_39.thumb.png.9723f36feb97d3b6f274e46d9c27b7c4.png

Share this post


Link to post

wtf, Paolo, that's amazing! you are fantastic.

 

the Fox mill’s website is a mess, but i have a set i downloaded ages ago (the profiles have not changed). I will PM you a link.

  • Like 2

Share this post


Link to post

leaving this here for future searches...

 

here’s a quick terminal one-liner (using perl) to round numbers in a file.

perl -i -pe 's/[-+]?\d*(?:\.?\d|\d\.)\d*(?:[eE][-+]?\d+)?/sprintf("%.4f",$&)/ge' [file]

-i makes the changes “in place,” and "%.4f" in the sprintf controls the decimal places (in this case, 4 places)

 

be careful—this is fast, and powerful, and it will check EVERY number it finds (Add2DVertex will become Add2.0000DVertex, Pos1.x will become Pos1.0000x)

 

a text file like this...

 

Quote

BeginPoly;
  MoveTo(0.499999999999993",1.906219242922759");
  LineTo(0.499999999999993",2.281587995185734");
  ArcTo(0.336161617660406",2.273621677836189",0.156250000000001");
  ArcTo(0.336161617660406",2.601685560272307",0.156250000000001");
  LineTo(0.499999999999993",2.593719242922763");
  LineTo(0.499999999999993",2.969087995185738");
  ArcTo(0.336161617660406",2.961121677836175",0.156250000000001");
  ArcTo(0.336161617660406",3.289185560272311",0.156250000000001");
  LineTo(0.499999999999993",3.281219242922766");
  LineTo(0.499999999999993",3.499999999999986");
  LineTo(0",3.499999999999986");
  LineTo(0",0");
  LineTo(0.499999999999993",0");
  LineTo(0.499999999999993",0.219087995185741");
  ArcTo(0.336161617660406",0.211121677836178",0.156250000000001");
  ArcTo(0.336161617660406",0.539185560272296",0.156250000000001");
  LineTo(0.499999999999993",0.531219242922752");
  LineTo(0.499999999999993",0.906587995185727");
  ArcTo(0.336161617660406",0.898621677836182",0.156250000000001");
  ArcTo(0.336161617660406",1.2266855602723",0.156250000000001");
  LineTo(0.499999999999993",1.218719242922755");
  LineTo(0.499999999999993",1.59408799518573");
  ArcTo(0.336161617660406",1.586121677836186",0.156250000000001");
  ArcTo(0.336161617660406",1.914185560272321",0.156250000000001");
EndPoly;

 

comes out like this...

Quote

BeginPoly;
  MoveTo(0.5000",1.9062");
  LineTo(0.5000",2.2816");
  ArcTo(0.3362",2.2736",0.1563");
  ArcTo(0.3362",2.6017",0.1563");
  LineTo(0.5000",2.5937");
  LineTo(0.5000",2.9691");
  ArcTo(0.3362",2.9611",0.1563");
  ArcTo(0.3362",3.2892",0.1563");
  LineTo(0.5000",3.2812");
  LineTo(0.5000",3.5000");
  LineTo(0.0000",3.5000");
  LineTo(0.0000",0.0000");
  LineTo(0.5000",0.0000");
  LineTo(0.5000",0.2191");
  ArcTo(0.3362",0.2111",0.1563");
  ArcTo(0.3362",0.5392",0.1563");
  LineTo(0.5000",0.5312");
  LineTo(0.5000",0.9066");
  ArcTo(0.3362",0.8986",0.1563");
  ArcTo(0.3362",1.2267",0.1563");
  LineTo(0.5000",1.2187");
  LineTo(0.5000",1.5941");
  ArcTo(0.3362",1.5861",0.1563");
  ArcTo(0.3362",1.9142",0.1563");
EndPoly;

 

then a little manual cleaning will get it down further... (there’s probably syntax that would strip leading and trailing zeros, but i wanted to post this while i was thinking of it)

Quote

BeginPoly;
  MoveTo(0.5",1.9062");
  LineTo(0.5",2.2816");
  ArcTo(0.3362",2.2736",0.1563");
  ArcTo(0.3362",2.6017",0.1563");
  LineTo(0.5",2.5937");
  LineTo(0.5",2.9691");
  ArcTo(0.3362",2.9611",0.1563");
  ArcTo(0.3362",3.2892",0.1563");
  LineTo(0.5",3.2812");
  LineTo(0.5",3.5");
  LineTo(0",3.5");
  LineTo(0",0");
  LineTo(0.5",0");
  LineTo(0.5",0.2191");
  ArcTo(0.3362",0.2111",0.1563");
  ArcTo(0.3362",0.5392",0.1563");
  LineTo(0.5",0.5312");
  LineTo(0.5",0.9066");
  ArcTo(0.3362",0.8986",0.1563");
  ArcTo(0.3362",1.2267",0.1563");
  LineTo(0.5",1.2187");
  LineTo(0.5",1.5941");
  ArcTo(0.3362",1.5861",0.1563");
  ArcTo(0.3362",1.9142",0.1563");
EndPoly;

 

—AE

  • Like 1

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...