The Hamma Posted July 7, 2023 Share Posted July 7, 2023 (edited) 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. Edited July 7, 2023 by The Hamma Quote Link to comment
Jesse Cogswell Posted July 7, 2023 Share Posted July 7, 2023 What you'll want to do is use ValidNumStr to convert the value. 1 Quote Link to comment
The Hamma Posted July 7, 2023 Author Share Posted July 7, 2023 1 hour ago, Jesse Cogswell said: What you'll want to do is use ValidNumStr to convert the value. Got it, Thanks. It would have been easier to find if it were Num2StrValid, LOL! Quote Link to comment
Maury Jensen Posted December 24, 2023 Share Posted December 24, 2023 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. Any insights appreciated, VW 2024 file attached. get number from record problem.vwx Quote Link to comment
Jesse Cogswell Posted December 24, 2023 Share Posted December 24, 2023 @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: Quote Link to comment
Pat Stanford Posted December 24, 2023 Share Posted December 24, 2023 Did you try it Jesse? Because I did try it and couldn't make it work. It looks like just a number, but the Float returns a message: My Python is not strong enough to know if Python Float should convert a string or not. Quote Link to comment
Maury Jensen Posted December 24, 2023 Share Posted December 24, 2023 @Jesse Cogswell Thanks. I tried using the float node earlier, but it resulted in an error. see this screen shot. What am I missing? I also did see that thread you linked to, but could not figure out exactly how to put the function into a user function node. Quote Link to comment
Jesse Cogswell Posted December 24, 2023 Share Posted December 24, 2023 (edited) 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 December 25, 2023 by Jesse Cogswell Quote Link to comment
Jesse Cogswell Posted December 24, 2023 Share Posted December 24, 2023 I didn't try the Float node while pulling from a Record Format, just having a manual string input a la: That seemed to work fine. The Str2Num node that I built does indeed work with pulling values from a record format, though. The attached example uses a Dimension Tape to set the width of the Marionette rectangle. Str2Num Marionette Example.vwx Quote Link to comment
Jesse Cogswell Posted December 25, 2023 Share Posted December 25, 2023 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 Quote Link to comment
Maury Jensen Posted December 25, 2023 Share Posted December 25, 2023 @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. Quote Link to comment
Maury Jensen Posted December 25, 2023 Share Posted December 25, 2023 @Jesse Cogswell I solved my own question about the output being two lines. I mistakenly had two connections to the get record field node HObj input resulting in two lines of output. With that removed, the float node also works properly, without needing the split node. Thanks for your help! Quote Link to comment
Recommended Posts
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.