How should I use the zbrush script to display the distance between 2 points? Do I need to memorize the first point first, and then the second point, but I can’t write the code. Can you help me solve it?
You would just set two variables, one for the starting point and one for the end point, then use those values to calculate the distance using pythagoras’ theorem.
Thank you for your suggestion, can you give me some code guidance
It’s not all that difficult. The main problem is how you select the two points. In this example, a note is displayed after pressing the button. While the note is showing, put your cursor over where you want the first point to be, then press Enter on the keyboard to dismiss the note. The zscript will record the first point. A second note will be displayed and you repeat the process to select the second point. After pressing Enter a third note will be displayed showing the distance between the two points.
[RoutineDef,GetDistance,
[VarSet,distance,SQRT((HLength*HLength)+(VLength*VLength))]
,HLength,VLength,distance]
[IButton,"Find Distance","Find distance in pixels between two points",
[Note,"\Cff9C00Place cursor over the first point and press \CffffffEnter"]
[VarSet,StartHPos,[MouseHPos,1]]//global coordinates - top left of UI is 0,0
[VarSet,StartVPos,[MouseVPos,1]]
[Note,[StrMerge,"\Cff9C00Start point set to \Cffffff",StartHPos," : ",StartVPos],,-1]
[Note,"\n\n\Cff9C00Place cursor over the second point and press \CffffffEnter"]
[VarSet,EndHPos,[MouseHPos,1]]
[VarSet,EndVPos,[MouseVPos,1]]
[VarSet,result,0]
[RoutineCall,GetDistance,EndHPos-StartHPos,EndVPos-StartVPos,result]
[Note,[StrMerge,"\Cff9C00Start point set to \Cffffff",StartHPos," : ",StartVPos],,-1]
[Note,[StrMerge,"\n\Cff9C00End point set to \Cffffff",EndHPos," : ",EndVPos],,-1]
[Note,[StrMerge,"\n\n\Cff9C00Distance between points is \Cffffff",result]]
]
HTH,
Marcus
Thank you so much for your guidance, thank you
I think I’ve misunderstood what you were asking for! If you want the Transpose Action line length then you can get it directly:
[IButton,"Show Transpose Length","Show the length of the action line",
[If,[TransposeIsShown],
[TransposeGet,StartXPos,StartYPos,StartZPos,EndXPos,EndYPos,EndZPos,ActionLineLength]
[Note,ActionLineLength]
]
]
HTH,
Marcus
The zscript commands are outlined in the Command Reference here:
http://docs.pixologic.com/user-guide/customizing-zbrush/zscripting/command-reference/
Thank you very much, thank you
Thank you very much, thank you
Hello, your previous instructions are helpful to me. I have one last question. I want to set 3 buttons separately. The first button sets the start point, the second button sets the end point, and the third button is displayed at 2 o’clock. What should I do? I also studied for 3 hours, but did not get the desired result, so I still want to ask you!
OK, here’s some code that may help. I’m not sure what you mean by “the third button is displayed at 2 o’clock” but perhaps you can adapt this to your needs. What you do is click on the mesh where you want the starting point to be and then click the “Store Start” button. This records the first point. You do the same for the “Store End” button. It’s important that you click on the mesh and immediately press the button because otherwise it might not record the point correctly. (The zscript repeats the last mouse click using the Transpose line so that the coordinates can be recorded.)
The third “Show” button will display the length in a Note and in the NoteBar at the top left of the UI. It will also create a new Transpose line after the Note is dispelled, though that isn’t needed for the length calculation.
HTH,
Marcus
[VarDef,StartXPos,0]
[VarDef,StartYPos,0]
[VarDef,StartZPos,0]
[VarDef,EndXPos,0]
[VarDef,EndYPos,0]
[VarDef,EndZPos,0]
[VarDef,ActionLineLength,0]
[VarDef,drawState,0]
[VarDef,moveState,0]
[VarDef,scaleState,0]
[VarDef,rotateState,0]
[RoutineDef,ModeState,
[If,store,
[VarSet,drawState,[IGet,Transform:Draw Pointer]]
[VarSet,moveState,[IGet,Transform:Move]]
[VarSet,scaleState,[IGet,Transform:Scale]]
[VarSet,rotateState,[IGet,Transform:Rotate]]
[ISet,Transform:Move,1]//Move turned on so Gizmo/Transpose Line shows
,//else restore
[ISet,Transform:Draw Pointer,drawState]
[ISet,Transform:Move,moveState]
[ISet,Transform:Scale,scaleState]
[ISet,Transform:Rotate,rotateState]
]
,store]
[IButton,"Store Start","Click mesh for Start point and then press this button",
[If,[IGet,Transform:Edit],
[IFreeze,//hide the actions from the user
[RoutineCall,ModeState,1] //store mode
[IPress,Stroke:Replay Last]
[If,[TransposeIsShown],
[TransposeGet,StartXPos,StartYPos,StartZPos]
]
[RoutineCall,ModeState,0]//restore mode
]
]
]
[IButton,"Store End","Click mesh for End point and then press this button",
[If,[IGet,Transform:Edit],
[IFreeze,
[RoutineCall,ModeState,1]
[IPress,Stroke:Replay Last]
[If,[TransposeIsShown],
[TransposeGet,EndXPos,EndYPos,EndZPos]
]
[RoutineCall,ModeState,0]
]
]
]
[IButton,"Show","Show new Transpose line and display length",
[If,[IGet,Transform:Edit],
[IPress,Transform:Move]//so Transpose line will be visible
[IUnPress,Transform:Gizmo 3D]
[VarSet,length,SQRT(((EndXPos-StartXPos)*(EndXPos-StartXPos))+((EndYPos-StartYPos)*(EndYPos-StartYPos))+((EndZPos-StartZPos)*(EndZPos-StartZPos)))]
[TransposeSet,StartXPos,StartYPos,StartZPos,EndXPos,EndYPos,EndZPos,length]
[Note,[StrMerge,"\Cff9C00\Cff9C00Length between points is: \Cff9C00\Cffffff",length," units"]]
[NoteBar,[StrMerge,"\Cff9C00Length between points is: \Cffffff",length," units"]] //this displays top left of UI
]
]
Thank you so much, thank you very much
You can get it using the TransposeGet command:
[If,[TransposeIsShown],
[TransposeGet,StartXpos,StartYpos,StartZpos,EndXpos,EndYpos,EndZpos,length]
[Note,length]
]
Marcus
Thank you very much for your reply, thank you! I mean can I customize this size. For example, I pull out an operation line with a start point and an end point. Can I set the size between them? Instead of the display size. Thanks again
Yes, you simply use the “length” variable in [TransposeSet] to set the length to what you want:
-
Get the start and end XYZ positions using TransposeGet:
[TransposeGet,StartXpos,StartYpos,StartZpos,EndXpos,EndYpos,EndZpos]
-
Set the length you want:
[VarSet,length,0.5] [TransposeSet,StartXpos,StartYpos,StartZpos,EndXpos,EndYpos,EndZpos,length]
Marcus
Thank you very much for being able to help me again, this idea is very good, I think I’m one step closer. I have the last problem now. Can I scale the model together when setting the size? Instead of operating line changes individually. Thanks again!
You could set the Tool>Geometry>XYZ Size to what you want at the same time. You will need the existing measurement for the thickness you are measuring, so that you can calculate how much you need to scale by.
But one thing that you may need to take account of is the way the new size of the object will affect the Transpose line position. The scaling will happen outward from the origin so if (for example) the Transpose line started at the outer edge then after scaling this will no longer be the correct position for measuring.
Thanks again, I will test it