Jump to content
Developer Wiki and Function Reference Links ×

Displaying dimension next to cube made in Marionette Network


Eaglerulez

Recommended Posts

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!

Marionette Network.JPG

Desired Result.JPG

Marionette Output.JPG

Link to comment

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:

grafik.thumb.png.a1aefdfa0e4579770adbac98d3f36dee.png

 

 

Regards,

Letti

Link to comment

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

Link to comment
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!

Link to comment

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 by Letti R
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...