Jump to content
Developer Wiki and Function Reference Links ×

Convert dimension value from Record field to Real number


Recommended Posts

I have a Number(Dimension) record attached to a symbol.  When I use GetRField to get the value of that dimension it returns a STRING.  The value is ( 4" ).  When I use Str2Num that value becomes 0.  Is there a way to convert STRING Dimensions into REAL numbers?

 

If I use General Number format it works fine but then I have to keep all my units in inches rather than feet and inches. 

 

Also I would like to let it use Document Units so I don't think looking for the ' or " unit mark would be helpful.  

 

image.png.cc8678dbbdb165770d6e4345259db236.png

Edited by The Hamma
Link to comment
  • 5 months later...

Hi guys,

 

Came across this thread when searching for how to convert a string from a record to a real number for use in my marionette network. 

 

Basically I need to get numbers from the an attached symbol record, add some other numbers to that data, then use it to set a point.  Then I'm using that point to move existing geometry, (the rectangle in the document). 

 

The data from the record is showing up as a string. I can't figure out how to convert it into a real number that can be used in the math nodes.

 

I'm brand new to this and don't fully understand why the output from the record is what it is, but it clearly does not work as a number.  I know this thread is about more strait up scripting rather than marionette nodes, but I'm thinking the solution to my problem is similar to what you're talking about here.  But I can't figure out how to implement the functions you're talking about in marionette. 

Screenshot.thumb.jpg.900ae9327137b2df4d909d17e9983740.jpg

Any insights appreciated, VW 2024 file attached.

 

get number from record problem.vwx

Link to comment

@Maury Jensen You will need to add a Float node between the Get Record Field and Add nodes.  This should convert the string into a float value for the addition.  However, keep in mind that this will only work if there aren't unit specifiers saved in the record field (', ", m, cm, mm, etc).  If there are, you will need to remove them using a User Function node as specified in this thread:

 

Link to comment

Or you can use this Marionette node that I just fabbed up.  It works exactly like the ValidNumStr function that will properly convert a string value from a record format into a dimensional float value while also using the units specifier.  I think it's a huge oversight to not have a node like this in the standard Marionette library.

Str2NumF Marionette Node.vwx

Edited by Jesse Cogswell
Link to comment

For those curious, the Python code in the Marionette node is very simple:

 

#Created 12/24/2023 Jesse Cogswell
@Marionette.NodeDefinition
class Params(metaclass = Marionette.OrderedClass):
#APPEARANCE
	#Name
	this = Marionette.Node( "Str2NumF" )
	this.SetDescription( 'Allows a user to convert a string value to a float value' )
	
	#Input Ports
	x = Marionette.PortIn( 0,'s' )
	x.SetDescription( "a string value" )	
	
	#OIP Controls
	
	#Output Ports
	y = Marionette.PortOut('n')
	y.SetDescription( "result float value" )
	
#BEHAVIOR

def RunNode(self):
	#Libraries
	import math
	import vs

	#inputs
	x = self.Params.x.value
	
	#script
	b,y = vs.ValidNumStr(x)
	
	#outputs
	self.Params.y.value = y

 

Link to comment

@Jesse Cogswell Thanks so much for your insights on this!   The string output from the get record field node is two lines a "0" line and a "1" line.  I don't know why that is.  In you example you are using the tape measure record, which seems to be outputting a single number from its field. 

 

What I did is add a split node that seemed to remove the first line, making it a single number and useable by the add node.  I've only got one field in the record, any idea why it would output two lines for the string?  I'm also not exactly sure why the split node is giving me the correct output.  But, in the end, it is doing what i need by providing a single number to the add node. 

 

addedsplitnode.thumb.jpg.f42e423ab1df3d367b525d7da670faec.jpg

Link to comment

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.

×
×
  • Create New...