How can I assign new value(“prompt”) to the TextFields by scripting?
There’s a class named “TexteFields” under Rhino.Runtime, and they are all static methods.
I couldn’t find a method allow me to assign new value(prompt, if I used the language in the rhinoCommon).
So, basically I have a block from AutoCAD in the similar structure, and I want to assigning new values inside those text fields.
I know the block in RhinoCommon, I should look up the InstanceDefinition class.
This function do get the name, prompt and the defaultValue.
Just wanna ask if there’s a way I can assgin a new value(prompt) to these textfields.
Some tests I tried.
And the files are attached, Thanks.
BlockAttributeLearning.3dm (1.1 MB)
BlockAttributeLearning.gh (15.2 KB)
dale
(Dale Fugier)
June 3, 2022, 7:15pm
2
Hi @aesthetik0717 ,
I’m not sure I understand what you are looking to do. But this list:
Is not extendable.
Or am I confused? Please you can try to clarify what you are trying to do?
Thanks,
– Dale
Thanks for the reply. I want to assign the new value to these fields.
I know that textFields can do automation with simple fx logic, which I want to do it by scripting in Grasshopper. However, I would need to a way to set the new value to those fields.
I found that I can access those fields’ texts by TextFields methods, but all of them are only for get (getter), not allow we to set the new value (setter).
I also know that we can use macro SetUserText
to do the job, but still wonder if there’s a setter in TextField class or other class that can allow me to change the value to those fields?
private void RunScript(bool btn, Guid frameId, object x, ref object A)
{
if(!btn){
return;
}
RhinoDoc.ActiveDoc.Objects.Select(frameId);
RhinoApp.RunScript("_-SetUserText 設計者 Jim", false);
RhinoApp.RunScript("_-SetUserText 設計者 Jim2", false);
RhinoDoc.ActiveDoc.Objects.UnselectAll();
}
Thanks.
dale
(Dale Fugier)
June 6, 2022, 9:12pm
4
Hi @aesthetik0717 ,
How about this?
public void TestUserText(RhinoDoc doc, Guid objectId)
{
if (null != doc)
{
var rhinoObject = doc.Objects.FindId(objectId);
{
if (null != rhinoObject)
{
var attributes = rhinoObject.Attributes.Duplicate();
attributes.SetUserString("Name", "Jim");
attributes.SetUserString("Occupation", "Designer");
doc.Objects.ModifyAttributes(rhinoObject, attributes, false);
}
}
}
}
– Dale
1 Like
Dale Fugier:
public void TestUserText(RhinoDoc doc, Guid objectId)
{
if (null != doc)
{
var rhinoObject = doc.Objects.FindId(objectId);
{
if (null != rhinoObject)
{
var attributes = rhinoObject.Attributes.Duplicate();
attributes.SetUserString("Name", "Jim");
attributes.SetUserString("Occupation", "Designer");
doc.Objects.ModifyAttributes(rhinoObject, attributes, false);
}
}
}
}
Thanks, it works perfectly!