Hello everyone,
I've tried to search the web but was unsuccessful in finding the right answer to the question that I have.
I want to determine the steps I need to perform to connect 2 objects (such as spheres) with a line/cylinder that will extend past both of them (such as per the picture below).
Right now, I'm creating a long cylinder and placing the tip at the middle of one sphere, and manually aligning the rest of the cylinder to the second sphere, but as you can imagine - it's not accurate.
Any ways to do this properly?
Also, an option of extending/shortening the cylinder later would be great too, since I didn't find how to do that either
Solved! Go to Solution.
Hello everyone,
I've tried to search the web but was unsuccessful in finding the right answer to the question that I have.
I want to determine the steps I need to perform to connect 2 objects (such as spheres) with a line/cylinder that will extend past both of them (such as per the picture below).
Right now, I'm creating a long cylinder and placing the tip at the middle of one sphere, and manually aligning the rest of the cylinder to the second sphere, but as you can imagine - it's not accurate.
Any ways to do this properly?
Also, an option of extending/shortening the cylinder later would be great too, since I didn't find how to do that either
Solved! Go to Solution.
Solved by miledrizk. Go to Solution.
The first question I would ask is "do you really need a cylinder between the two spheres"? Could you use a line with a renderable radial cross section like this? It would look the same as having a cylinder.
If you really need a cylinder I would create a cylinder (using pivot snaps) located at one of the spheres and then use a look-at constraint (Animation, Constraints, LookAt Constraint), click the other sphere and then check the Z axis. You can eyeball the height of the cylinder or use Tools, Measure Distance to get an exact value.
The first question I would ask is "do you really need a cylinder between the two spheres"? Could you use a line with a renderable radial cross section like this? It would look the same as having a cylinder.
If you really need a cylinder I would create a cylinder (using pivot snaps) located at one of the spheres and then use a look-at constraint (Animation, Constraints, LookAt Constraint), click the other sphere and then check the Z axis. You can eyeball the height of the cylinder or use Tools, Measure Distance to get an exact value.
Hi,
You'll find attached a link to a video explaining how to do that using a small script,
The text file containing the script will be attached here too.
The script: https://drive.google.com/file/d/1qhiEj4pN85Ikf3VSigE-i9CqOgYeAUeW/view?usp=sharing
And the Video explaining all the steps: https://youtu.be/ZbHZUvKYzlc
Hi,
You'll find attached a link to a video explaining how to do that using a small script,
The text file containing the script will be attached here too.
The script: https://drive.google.com/file/d/1qhiEj4pN85Ikf3VSigE-i9CqOgYeAUeW/view?usp=sharing
And the Video explaining all the steps: https://youtu.be/ZbHZUvKYzlc
Here's a script that will creates a cylinder between two selected object. The script has the radius of the cylinder set to 2 but that could easily be changed.
-- creates a cylinder of radius 2 between the centers of two selected objects. -- L. Minardi 1/21/2018 if selection.count > 1 then ( for i in 1 to $.count do ( p1 = $[1].pos p2 = $[2].pos ) p3 = p2-p1 plen = length(p3) p3u = p3/plen mycyl = cylinder radius:2 height:plen position:p1 -- <-- set radius as desired mycyl.transform = translate (matrixfromnormal p3u) p1 redrawViews() ) else (messagebox "Please select 2 objects.")
I still think the best process is to create renderable lines between the spheres. After creating the spline add a Spline IK Control modifier and add helper control objects and link them to the spheres. This will let you move the spheres in 3D and the "cylinders" will follow. Try moving the spheres in the attached Max file.
Here's a script that will creates a cylinder between two selected object. The script has the radius of the cylinder set to 2 but that could easily be changed.
-- creates a cylinder of radius 2 between the centers of two selected objects. -- L. Minardi 1/21/2018 if selection.count > 1 then ( for i in 1 to $.count do ( p1 = $[1].pos p2 = $[2].pos ) p3 = p2-p1 plen = length(p3) p3u = p3/plen mycyl = cylinder radius:2 height:plen position:p1 -- <-- set radius as desired mycyl.transform = translate (matrixfromnormal p3u) p1 redrawViews() ) else (messagebox "Please select 2 objects.")
I still think the best process is to create renderable lines between the spheres. After creating the spline add a Spline IK Control modifier and add helper control objects and link them to the spheres. This will let you move the spheres in 3D and the "cylinders" will follow. Try moving the spheres in the attached Max file.
@leeminardi this is a good script,
I just noticed two problems in it:
1- the p1 and p2 are short lived variables since they are inside a for loop, so p3 = p2 - p1 will result in an error because p2 and p1
became undefined values for maxscript. As a result the script will not run.
2- Now fixing by just dropping the closing parenthesis after the redrawviews() function will fix it but will create another problem, because now,
that will create two cylinders instead of one, since we're looping twice.
If we look carefully we don't need the for loop anyway.
the script can be simplified to:
if selection.count > 1 then
(
p1 = $[1].pos
p2 = $[2].pos
p3 = p2-p1
plen = length(p3)
p3u = p3/plen
mycyl = cylinder radius:2 height:plen position:p1 -- <-- set radius as desired
mycyl.transform = translate (matrixfromnormal p3u) p1
redrawViews()
)
else
(messagebox "Please select 2 objects.")
This time the script will work properly and will create one cylinder.
@leeminardi this is a good script,
I just noticed two problems in it:
1- the p1 and p2 are short lived variables since they are inside a for loop, so p3 = p2 - p1 will result in an error because p2 and p1
became undefined values for maxscript. As a result the script will not run.
2- Now fixing by just dropping the closing parenthesis after the redrawviews() function will fix it but will create another problem, because now,
that will create two cylinders instead of one, since we're looping twice.
If we look carefully we don't need the for loop anyway.
the script can be simplified to:
if selection.count > 1 then
(
p1 = $[1].pos
p2 = $[2].pos
p3 = p2-p1
plen = length(p3)
p3u = p3/plen
mycyl = cylinder radius:2 height:plen position:p1 -- <-- set radius as desired
mycyl.transform = translate (matrixfromnormal p3u) p1
redrawViews()
)
else
(messagebox "Please select 2 objects.")
This time the script will work properly and will create one cylinder.
@miledrizk Thank you for your comments. It may be true that p1 and p2 are short lived but they live long enough to define the rest of the variables. I tested my script several times and it works.
Did you actually try my script?
I tried the script with your edits and got the following error.
I am very new to Maxscripts and was not sure of the best way to define two named variables that were object properties. I thought there should be a cleaner way than using the for loop that I have in my code. But again, it works!
Lee
@miledrizk Thank you for your comments. It may be true that p1 and p2 are short lived but they live long enough to define the rest of the variables. I tested my script several times and it works.
Did you actually try my script?
I tried the script with your edits and got the following error.
I am very new to Maxscripts and was not sure of the best way to define two named variables that were object properties. I thought there should be a cleaner way than using the for loop that I have in my code. But again, it works!
Lee
Hi,
yes i did try the script and it gave me this error message:
which is normal because, to be able to maintain the life of those two variables you need to declare them before entering the for loop,
this way they become local variables in the if context not the for loop context,
If you like to keep your script the way it is it can be done simply by adding one line before the for loop which is: local p1, p2
Now it works
As for the modified script i made: it works also
Hi,
yes i did try the script and it gave me this error message:
which is normal because, to be able to maintain the life of those two variables you need to declare them before entering the for loop,
this way they become local variables in the if context not the for loop context,
If you like to keep your script the way it is it can be done simply by adding one line before the for loop which is: local p1, p2
Now it works
As for the modified script i made: it works also
@miledrizk I closed and reopened Max and was then able to successfully execute the version of my script with your edits. I had trouble finding documentation of how to reference individual elements of selected objects. The $[n] format is so simple but difficult to find. Thank you for the tip.
Here then is the final code for the script for @Anonymous.
-- creates a cylinder of radius 2 between two selected objects. -- edit the radius value in line 10 as required. if selection.count > 1 then ( p1 = $[1].pos p2 = $[2].pos p3 = p2-p1 plen = length(p3) p3u = p3/plen mycyl = cylinder radius:2 height:plen position:p1 -- <-- set radius as desired mycyl.transform = translate (matrixfromnormal p3u) p1 redrawViews() ) else (messagebox "Please select 2 objects.")
@miledrizk I closed and reopened Max and was then able to successfully execute the version of my script with your edits. I had trouble finding documentation of how to reference individual elements of selected objects. The $[n] format is so simple but difficult to find. Thank you for the tip.
Here then is the final code for the script for @Anonymous.
-- creates a cylinder of radius 2 between two selected objects. -- edit the radius value in line 10 as required. if selection.count > 1 then ( p1 = $[1].pos p2 = $[2].pos p3 = p2-p1 plen = length(p3) p3u = p3/plen mycyl = cylinder radius:2 height:plen position:p1 -- <-- set radius as desired mycyl.transform = translate (matrixfromnormal p3u) p1 redrawViews() ) else (messagebox "Please select 2 objects.")
Thank you so much for help!
I now have another question.
When I connect the two spheres with a cylinder/line, and extend the line past the spheres, I would like to add a semi-transparent cone that would come out of one of the spheres and extend along the line that would show a +/- 5 degrees radius.
How do I go about that?
Thank you so much for help!
I now have another question.
When I connect the two spheres with a cylinder/line, and extend the line past the spheres, I would like to add a semi-transparent cone that would come out of one of the spheres and extend along the line that would show a +/- 5 degrees radius.
How do I go about that?
Hi,
I updated my original script,
I also made a Screencast to show you how to use it,
Please find attached the text file here: https://drive.google.com/file/d/16H-Vt9CYe_eyBjU5KSQyTMD3hDru1uoG/view?usp=sharing
Hi,
I updated my original script,
I also made a Screencast to show you how to use it,
Please find attached the text file here: https://drive.google.com/file/d/16H-Vt9CYe_eyBjU5KSQyTMD3hDru1uoG/view?usp=sharing
Hi,
For the Cylinder length you can update the text by going to the second chunk, responsible for positioning the cylinder,
And the second line "target_cyl.height = length(dir)+(obj1.radius + obj2.radius)*2"
Keep the part "target_cyl.height = length(dir)" as it makes the cylinder's height equals the distance between the centers of the spheres,
Then type "+" (without the quotation marks) and add the amount you like. Just remember to update the Cylinder, you need to choose all the chunk
responsible for the Cylinder Position and click the Shift+Enter not just this line.
For the first request i'll try to update it.
So if i understood correctly you need the Cone's tip to be at the beginning of the Cylinder(close to sphere 1) and extends
only to this near sphere(sphere 1), no Cone between the two spheres.
Hi,
For the Cylinder length you can update the text by going to the second chunk, responsible for positioning the cylinder,
And the second line "target_cyl.height = length(dir)+(obj1.radius + obj2.radius)*2"
Keep the part "target_cyl.height = length(dir)" as it makes the cylinder's height equals the distance between the centers of the spheres,
Then type "+" (without the quotation marks) and add the amount you like. Just remember to update the Cylinder, you need to choose all the chunk
responsible for the Cylinder Position and click the Shift+Enter not just this line.
For the first request i'll try to update it.
So if i understood correctly you need the Cone's tip to be at the beginning of the Cylinder(close to sphere 1) and extends
only to this near sphere(sphere 1), no Cone between the two spheres.
Not quite. Attaching a simple drawing to explain what I need
Not quite. Attaching a simple drawing to explain what I need
Ah ok,
So the Tip starts at the sphere and the base goes at the end of the Cylinder,
I'll try to update it as soon as possible.
Now try the Cylinder Fix,
I need to relax a little, very tired! :))
Ah ok,
So the Tip starts at the sphere and the base goes at the end of the Cylinder,
I'll try to update it as soon as possible.
Now try the Cylinder Fix,
I need to relax a little, very tired! :))
Hi,
You'll find attached an updated version of the script:
https://drive.google.com/file/d/1Ttg04aTn8nhFcyMAzhyU-6r69xiBXKWa/view?usp=sharing
And another Screencast
Hi,
You'll find attached an updated version of the script:
https://drive.google.com/file/d/1Ttg04aTn8nhFcyMAzhyU-6r69xiBXKWa/view?usp=sharing
And another Screencast
Tried your scripts, they work really well, thank you!
Another question.
Anyway for me to link the cylinder to both spheres simultaniously? so that when they move the cylinder moves with them?
Tried your scripts, they work really well, thank you!
Another question.
Anyway for me to link the cylinder to both spheres simultaniously? so that when they move the cylinder moves with them?
Hi,
First welcome and glad it helped! 🙂
Now for the linking thing, there is a quick way and that's for me to update the script and make it
In a way that the two spheres and the cylinder become a group,
But in this case the three of them will move, rotate and scale at the same time,
But if you're thinking of moving only one, let's say one sphere to the left and make the Cylinder follows by rotating
And keep it's relation with both spheres the same. If that's the case it will complicate things and it will take more time
I have lots of work the coming two days, i give private lessons in Rhino so i need to prepare, maybe after that i can think
of something, if this is what you're thinking of,
Otherwise, if grouping is good enough for you i can update it for you
Hi,
First welcome and glad it helped! 🙂
Now for the linking thing, there is a quick way and that's for me to update the script and make it
In a way that the two spheres and the cylinder become a group,
But in this case the three of them will move, rotate and scale at the same time,
But if you're thinking of moving only one, let's say one sphere to the left and make the Cylinder follows by rotating
And keep it's relation with both spheres the same. If that's the case it will complicate things and it will take more time
I have lots of work the coming two days, i give private lessons in Rhino so i need to prepare, maybe after that i can think
of something, if this is what you're thinking of,
Otherwise, if grouping is good enough for you i can update it for you
Can't find what you're looking for? Ask the community or share your knowledge.