Transform.Scale vb.Net


#1

I’m sure this will be straight forward to many, so please forgive my inexperience while I get my head around the basics.

I am trying to scale some objects in only the Z axis by 2 and can not get any action. The following provides no result at all.

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    Dim go As New Rhino.Input.Custom.GetObject()
    go.SetCommandPrompt("Select objects")
    Dim center_point As New Rhino.Geometry.Point3d(0, 0, 0)
    Dim height_point As New Rhino.Geometry.Point3d(0, 0, 10)
    Dim zaxis As New Rhino.Geometry.Point3d(10, 3, 2)
    Dim plane As New Rhino.Geometry.Plane(center_point, height_point)
    Rhino.Geometry.Transform.Scale(plane, 1, 1, 2)
    Return
End Sub

(Menno Deij - van Rijswijk) #2

Check out the samples in the bottom part of this page http://wiki.mcneel.com/developer/rhinocommon

There are four main issues with your code. First, it is not run inside a command, but in an event handler. This is usually not a good idea because you are operating outside of Rhino’s undo system. It is possible to execute a command from an event handler using RhinoApp.RunScript(…).

Secondly you are not getting any objects. You should call go.Get() to do something with the GetObject.

Thirdly you are not applying the scaling transform to anything (that would be the obtained points).

Lastly, the document is not updated in any way. This is most easily done inside a command because then you have the reference to the document.


#3

Thanks for that, I think I have got some other parts working following the links and your recommendations. I still can’t get the transform to work, but will keep persisting with it. I know when I try to learn something new I jump right in. (Not interested in “hello world”!)

My plan is to run the transform by clicking on the button, so I am hoping to get that working, but I could look at running it from the command instead of from the button. I may seek further help yet, but will definitely trial a few more things.

Warm regards,

Adrian


(Menno Deij - van Rijswijk) #4

The recommended way is to make every action a command. That way you get a scriptable ecosystem of commands. Next, you can make a user interface that calls the commands when the user clicks a button.

Rhino itself is a prime example of this method. Each button runs a command. Some even run the same command, but with different command options.


#5

OK, here is where I am at now. It is in the main command now.
The first part works - it allows the selection of the object.

I have looked at the sample vb files, but it seems the version 4 ones have some differences?

Here is the code - just can’t get the scale to work…

Thanks again,

Adrian

        Dim rhobj As Rhino.DocObjects.ObjRef = Nothing
        Dim go = RhinoGet.GetOneObject("Select object", True, Rhino.DocObjects.ObjectType.AnyObject, rhobj)
        Return go

        Dim scalept As New Rhino.Geometry.Point3d(0, 0, 0)

        Rhino.Geometry.Transform.Scale(scalept, 2) ' NOT SURE WHAT TO DO WITH THIS LINE?
        Return Rhino.Commands.Result.Success

#6

This http://wiki.mcneel.com/developer/rhinocommonsamples/transformbrep should help you understand how to transform Rhino objects. Breps or points or other objects is the same.
Also, what should

Return go

do ?


#7

Thank you - it was that example I was trying to work from originally.
I think I was trying to trim lines out to see what was necessary, but obviously left some keys out.

The attached now works - so just confirming - line 1 doesn’t actually DO the transformation? This is my first time programming Object Orientated, so I am sure my lack of understanding relates to that.

In VBScript you would modify something in one line, but obviously here both of the lines following achieve 2 different things?

Thanks again for the help - I’m starting to understand a bit more.

Adrian

        Dim xform = Rhino.Geometry.Transform.Scale(scalept, 2)
        doc.Objects.Transform(rhobj, xform, True)
        doc.Views.Redraw()
        Return Rhino.Commands.Result.Success

#8

Hi @menno,

I found your comment on scale1d.

        Dim xform = Rhino.Geometry.Transform.Scale(scalept, 2)
        doc.Objects.Transform(rhobj, xform, True)
        doc.Views.Redraw()
        Return Rhino.Commands.Result.Success

I don’t seem to be able


#9

Yes, VBScript is simpler and shorter to write, but much less powerful.
It only works on objects from the Rhino document. RhinoCommon has not this limitation, you can play with all the objects you like without having a single point in your Rhino file.
About the script:
line 1 creates a Transform object, that actually specifies a transformation, which can then be applied to objects, if you like.
line 2 applies the transformation to the object, modifying the object in the Rhino document
line 3 simply redraws the views, to let you see that the object has been transformed

(I hope these words make some sense, despite my poor English and my poor logic …)


#10

I don’t seem to be able to enter an array of varying x,y,z scale factors.

Thanks,

Adrian


#11

Yes, that does make sense. No problems with your english at all :slight_smile: The biggest language barrier here is my efforts to learn vb.net!


#12

GOT IT, sorry for the many posts!.

Adrian


#13

Thanks @menno & @emilio!


#14

You’re welcome, Adrian.
Glad to have one more RhinoCommon user around here in the forum … more chances to help each other. :smiley:
Happy coding !