Eaglerulez Posted December 12, 2023 Share Posted December 12, 2023 Hi there, I am trying to make a simple Marionette node where I can make a cube extrude and have the dimension for the extrude displayed next to the cube. I have attached a screenshot of my current Marionette network, my current output, and my desired outcome. I think I have (2) main challenges that I haven't been able to figure out. -How to get dimensions to display with unit values and not several zeros behind it. -How to get multiple dimensions to be added cleanly within a single string/text box like my desired outcome. Any thoughts on how to best achieve this? Thanks so much! Quote Link to comment
Letti R Posted December 13, 2023 Share Posted December 13, 2023 Hello, when you use the "Dim" node with "feet and inches" it converts the input to inches. I think the zeroes are due to conversion error. To get rid of them you just can use the "round" node to round the value to the desired ammount of digits. As someone who never uses imperial units i dont know if there is an easy solution (in Marionette with no custom nodes) if you want to show your dimensions in feet and inches combined. However here is a Marionette that puts together a string with the three dimensions all in inches: Regards, Letti Quote Link to comment
Eaglerulez Posted December 14, 2023 Author Share Posted December 14, 2023 Awesome! Let me try this out on my end this is a very helpful step in the right direction I believe! Quote Link to comment
Letti R Posted December 15, 2023 Share Posted December 15, 2023 Hello, i had a bit of fun with this problem and wrote a custom node that converts a number that is given in inches to a string that is in feet and inches. Because i dont know anything about imperial units i just tried to replicate what is shown in the OIP of the "Dim" node. But you can chose if you want to display .5" as 1/2" or as .5" (same with .25" and .75") in the OIP of the custom node via two checkboxes. I realy hope that this custom node is not necessary and that someone will show an easier (built-in) way, but until then this node should be a good workarround. To create the node just go into any node and replace the whole code with the code provided below. Please test the node and make sure that it works as intended! @Marionette.NodeDefinition class Params(metaclass = Marionette.OrderedClass): #APPEARANCE #Name this = Marionette.Node( 'n inches to string feet and inches' ) this.SetDescription( 'n inches to string feet and inches' ) #Input Ports n_inches_input = Marionette.PortIn( 0, 'n inches' ) n_inches_input.SetDescription( 'n inches' ) i_round_input = Marionette.PortIn( 0, 'i round inches to' ) i_round_input.SetDescription( "i round inches to" ) #OIP Controls b_zero_input = Marionette.OIPControl( 'ZERO.X -> .X', Marionette.WidgetType.Bool, True) b_zero_input.SetDescription('ZERO.X -> .X') b_half_input = Marionette.OIPControl( '.5 -> 1/2', Marionette.WidgetType.Bool, True) b_half_input.SetDescription('.5 -> 1/2') b_quarter_input = Marionette.OIPControl( '.25 -> 1/4', Marionette.WidgetType.Bool, True) b_quarter_input.SetDescription('.25 -> 1/4') #Output Ports s_output = Marionette.PortOut('s feet and inches (rounded)') s_output.SetDescription( 's feet and inches (rounded)' ) #BEHAVIOR def RunNode(self): #inputs n_inches = self.Params.n_inches_input.value i_round = int(self.Params.i_round_input.value) b_zero = self.Params.b_zero_input.value b_half = self.Params.b_half_input.value b_quarter = self.Params.b_quarter_input.value # script temp_feet = str(int(n_inches // 12)) temp_inches = str(round(n_inches % 12, i_round)) temp_inches = temp_inches.rstrip(".0") if b_zero: temp_inches = temp_inches.lstrip("0") if b_half: if temp_inches[-2:] == ".5": temp_inches = temp_inches[:-2] + " 1/2" if b_quarter: if temp_inches[-3:] == ".25": temp_inches = temp_inches[:-3] + " 1/4" elif temp_inches[-3:] == ".75": temp_inches = temp_inches[:-3] + " 3/4" temp_output = temp_feet + "'" + temp_inches + '"' if temp_feet == "0": temp_output = temp_inches + '"' temp_output = temp_output.strip() #outputs self.Params.s_output.value = temp_output Regards, Letti Quote Link to comment
Eaglerulez Posted December 18, 2023 Author Share Posted December 18, 2023 Hi Letti, Thanks so much for this! I will give it a whirl and will keep you posted! Quote Link to comment
Eaglerulez Posted December 22, 2023 Author Share Posted December 22, 2023 On 12/15/2023 at 1:12 AM, Letti R said: Hello, i had a bit of fun with this problem and wrote a custom node that converts a number that is given in inches to a string that is in feet and inches. Because i dont know anything about imperial units i just tried to replicate what is shown in the OIP of the "Dim" node. But you can chose if you want to display .5" as 1/2" or as .5" (same with .25" and .75") in the OIP of the custom node via two checkboxes. I realy hope that this custom node is not necessary and that someone will show an easier (built-in) way, but until then this node should be a good workarround. To create the node just go into any node and replace the whole code with the code provided below. Please test the node and make sure that it works as intended! @Marionette.NodeDefinition class Params(metaclass = Marionette.OrderedClass): #APPEARANCE #Name this = Marionette.Node( 'n inches to string feet and inches' ) this.SetDescription( 'n inches to string feet and inches' ) #Input Ports n_inches_input = Marionette.PortIn( 0, 'n inches' ) n_inches_input.SetDescription( 'n inches' ) i_round_input = Marionette.PortIn( 0, 'i round inches to' ) i_round_input.SetDescription( "i round inches to" ) #OIP Controls b_zero_input = Marionette.OIPControl( 'ZERO.X -> .X', Marionette.WidgetType.Bool, True) b_zero_input.SetDescription('ZERO.X -> .X') b_half_input = Marionette.OIPControl( '.5 -> 1/2', Marionette.WidgetType.Bool, True) b_half_input.SetDescription('.5 -> 1/2') b_quarter_input = Marionette.OIPControl( '.25 -> 1/4', Marionette.WidgetType.Bool, True) b_quarter_input.SetDescription('.25 -> 1/4') #Output Ports s_output = Marionette.PortOut('s feet and inches (rounded)') s_output.SetDescription( 's feet and inches (rounded)' ) #BEHAVIOR def RunNode(self): #inputs n_inches = self.Params.n_inches_input.value i_round = int(self.Params.i_round_input.value) b_zero = self.Params.b_zero_input.value b_half = self.Params.b_half_input.value b_quarter = self.Params.b_quarter_input.value # script temp_feet = str(int(n_inches // 12)) temp_inches = str(round(n_inches % 12, i_round)) temp_inches = temp_inches.rstrip(".0") if b_zero: temp_inches = temp_inches.lstrip("0") if b_half: if temp_inches[-2:] == ".5": temp_inches = temp_inches[:-2] + " 1/2" if b_quarter: if temp_inches[-3:] == ".25": temp_inches = temp_inches[:-3] + " 1/4" elif temp_inches[-3:] == ".75": temp_inches = temp_inches[:-3] + " 3/4" temp_output = temp_feet + "'" + temp_inches + '"' if temp_feet == "0": temp_output = temp_inches + '"' temp_output = temp_output.strip() #outputs self.Params.s_output.value = temp_output Regards, Letti Hi Letti, Okay so everything generally is working well with this custom node however even foot measurements are not displaying quite as cleanly as I'd hope for. Basically if I type 5' in for the DIM the output ends up being 5'" instead of 5'. I think this is because the dim input automatically rounds 5' to 5'0" and your node maybe rounds the zero down but does not delete the inch marker afterwards? I think my ideal output would be 5' as opposed to 5'" or 5'0". Any thoughts on how to best address that? On the positive side 12'6" gets displayed properly. 3" gets displayed properly so those work well! Thanks so much in advance for your help! Quote Link to comment
Letti R Posted December 22, 2023 Share Posted December 22, 2023 (edited) Hello, thank you for your reply. This is definitely an error i did not see. Luckily it should be an easy fix. And i am still hoping that someone has a better solution than this. Here is the code for the updated node: @Marionette.NodeDefinition class Params(metaclass = Marionette.OrderedClass): #APPEARANCE #Name this = Marionette.Node( 'n inches to string feet and inches' ) this.SetDescription( 'n inches to string feet and inches' ) #Input Ports n_inches_input = Marionette.PortIn( 0, 'n inches' ) n_inches_input.SetDescription( 'n inches' ) i_round_input = Marionette.PortIn( 9, 'i round inches to' ) i_round_input.SetDescription( "i round inches to" ) #OIP Controls b_zero_input = Marionette.OIPControl( 'ZERO.X -> .X', Marionette.WidgetType.Bool, True) b_zero_input.SetDescription('ZERO.X -> .X') b_half_input = Marionette.OIPControl( '.5 -> 1/2', Marionette.WidgetType.Bool, True) b_half_input.SetDescription('.5 -> 1/2') b_quarter_input = Marionette.OIPControl( '.25 -> 1/4', Marionette.WidgetType.Bool, True) b_quarter_input.SetDescription('.25 -> 1/4') #Output Ports s_output = Marionette.PortOut('s feet and inches (rounded)') s_output.SetDescription( 's feet and inches (rounded)' ) #BEHAVIOR def RunNode(self): #inputs n_inches = self.Params.n_inches_input.value i_round = int(self.Params.i_round_input.value) b_zero = self.Params.b_zero_input.value b_half = self.Params.b_half_input.value b_quarter = self.Params.b_quarter_input.value # script temp_feet_num = int(n_inches // 12) temp_inches_num = round(n_inches % 12, i_round) temp_feet = str(temp_feet_num) temp_inches = str(temp_inches_num) temp_inches = temp_inches.rstrip(".0") if b_zero: temp_inches = temp_inches.lstrip("0") if b_half: if temp_inches[-2:] == ".5": temp_inches = temp_inches[:-2] + " 1/2" if b_quarter: if temp_inches[-3:] == ".25": temp_inches = temp_inches[:-3] + " 1/4" elif temp_inches[-3:] == ".75": temp_inches = temp_inches[:-3] + " 3/4" temp_feet = temp_feet + "'" temp_inches = temp_inches + '"' temp_output = temp_feet + temp_inches if temp_inches_num == 0: temp_output = temp_feet if temp_feet_num == 0: temp_output = temp_inches temp_output = temp_output.strip() #outputs self.Params.s_output.value = temp_output Please note that i also set the default value of "i round inches to" to 9 decimal places. This should eliminate most errors that occur due to floating point inaccuracies whilst beeing precise enough. But you can ofcourse set the value to what you need. Also please note that i only tested this node while the document units were set to "feet and inches". If you use some other setting like "feet" the return value of the node will be wrong because the input will most likely not be in inches (the input number has to be in inches). Ofcourse i could write the node so that i checks the current unit settings of the document and converts what ever the input is into feet and inches, but i hope that i can avoid that for it would take some time. Regards, Letti Edited December 22, 2023 by Letti R 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.