Grasshopper

algorithmic modeling for Rhino

how does one go about this? i am looking to do something similar to rhinoscript rhino.addtext, where one could add a number string (in my case, annotation number text or in grasshopper, a tag) of specific text size and font to a defined point in rhino viewport - the tag component of grasshopper does not seem to be able to work with data tree - i would like to add the same tag for each item per tree branch/path - seems this can only be resolved with vb scripting

Views: 1991

Replies to This Discussion

(lifted this from the Rhino SDK page) all seems to work except for the text is not displaying in the Grasshopper environment but will appear once added as an object to the Rhino document.


Sub RunScript(ByVal inPt As On3dPoint, ByVal height As Double)

Dim text As String = "point"
Dim font As String = "Arial"

Dim plane As New OnPlane(RhUtil.RhinoActiveCPlane())
plane.SetOrigin(inPt)

Dim text_entity As New OnTextEntity2()
Dim text_object As New MRhinoAnnotationText()
text_object.SetAnnotation(text_entity)
text_object.SetTextHeight(height)
text_object.SetString(text)
text_object.SetPlane(plane)

Dim bold As Boolean = False
Dim italic As Boolean = False
Dim idx As Integer = doc.m_font_table.FindOrCreateFont(font, bold, italic)
text_object.SetFontIndex(idx)

doc.AddObject(text_object)


End Sub
thanks for your reply ... yours together with guilio's response is very helpful...
btw, where on rhino SDK can i find this page???
Hi, I was working on this more or less at the same time as you, and I ended up adding the text to the document (yes, this is a workaround). It seems that for now we have to add the text object to the document in any case before we can to get its geometry - please if somebody knows more, tell us. The original component in C# is posted on the tools page. Because I know that some people are still liking VB better, I'm posting here a version for you in VB.

Btw, 100% of the (few) times I've tryed using developerfusion's translating utility from C# to VB, I got perfectly working code - sometimes even some problems got fixed. The same is not true in the opposite direction, because VB sintax for methods without signature can be the same as with properties, so very often the machine cannot tell the difference and the code is not valid. In this direction, there are also inconsistencies with array brackets - so the translation might be very far from being usable.
Attachments:
hi
many thanks for file... it worked ... so, fantastic (though will have to llive with having to add text object to document first)

btw, i struggled with the crvs array and had to convert the array to a List class in order to work with it eg the count(), add() etc method ... just for my understanding, what works with this "system.array" ... when i am typing in the code, the script allows for Sizeof() etc method but i get an error message at runtime saying that this method does not work with "system.array"??<>??
Is there a way to add an orientation input to this? When I try to rotate a series of text that I input to "content" about the "points," the text rotates off of that point.
Hey all,
this got me curious, so I tried to make a component using the Text Object command in Rhino. Its not pretty by any means...it has bits and pieces from all over. It would be useful for me to just have single stroke fonts as the output of the text, hence why I use this.

A few questions, how do I disable / enable view redrawing in vb.net? Looking at doc.Redraw or MRhinoView, etc...seems it would be at the doc level.

Let me know what you think and if there is a bunch of cruft (old moldy dirty code).
Luis
Attachments:
Just a quick update to disable the redraw while the text crvs are being generated... MRhinoView.EnableDrawing(False) >>> MRhinoView.EnableDrawing(True) seemed to do the job like in Rhinoscript ( Rhino.EnableRedraw() ).

This is really buggy and prone to breaking (uses sellast to grab the crvs) so user beware...might be just a good option to generate the text when the definition is ready...
Attachments:

When I tried to reworked this for RhinoCommon, like:

  Sub AddText(ByVal P As Point3d, ByVal T As String, ByVal H As Double, ByVal F As String, ByVal S As Integer)

    If (H <= 0) Then H = 1.0
    If (String.IsNullOrEmpty(F)) Then F = "Arial"
    If (S < 0 Or S > 3) Then S = 0


    Dim plane As New Plane
    plane.Origin = P

    Dim text_entity As New TextEntity()


    text_entity.TextHeight = H
    text_entity.Text = T
    text_entity.Plane = plane


    Dim bold As Boolean = False
    If (S = 1 Or S = 3) Then bold = True
    Dim italic As Boolean = False
    If (S = 2 Or S = 3) Then italic = True
    Dim idx As Integer = RhinoDocument.Fonts.FindOrCreate(F, bold, italic)
    text_entity.FontIndex = idx


    RhinoDocument.Objects.AddText(text_entity)

The Text seems to be created. I can select it in Rhino, but I do not see it. What am I missing?

Attachments:

Just for the record:

Dim objId As Guid = RhinoDocument.Objects.AddText(text_entity)

solves it.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service