×

工业设计互动平台

手机短信,快捷登录

微信登录,快人一步

QQ登录

只需一步,快速开始

访问电池的昵称

发布于 2014-11-11 0 点赞 1 评论 8330 浏览

外链图片
设为封片



感谢各位关注。新加入成员可以查看之前的消息记录。由于用户基础不一,我们要由浅入深,先讲基础操作,再讲工程实例,再到深入GHA开发,以及各种复杂算法。期间可能会穿插着来讲,可以直接回复问题,我们会尽量去解答。您觉得有用,请将此微信号分享给能用得着的朋友。
(本微信号文章如有转载请注明作者和出处,如用于商业用途请联系作者)
----------------------------------------------------------------------------------------------
下面原文链接是老婆大人在起点写的小说,有在起点上看小说的朋友希望能帮忙捧捧场,谢谢啦。
http://www.qdmm.com/MMWeb/2981855.aspx
-----------------------------------------------------------------------------------------------
我们来自江河梦小组(Scond Effect Group),工程用到gh,所以必须学习好GH插件,而大部分权威资料都来自国外,所以就组织组员翻译来自GH官方论坛的帖子,以便学习。本文由组员张桂钊翻译,GHA开发相关内容。
原文链接:http://www.grasshopper3d.com/forum/topics/accessing-the-name-of-a-custom?id=2985220%3ATopic%3A73340&page=1#comments
Permalink Reply by  on June 22, 2010 at 5:40am
hi luis
嗨,Luis

maybe look at this

Accessing the 'Name' of a custom component访问一个自定义组件的名称



  • Posted by Luis Fraguada on June 22, 2010     at 4:18am in VB, C# and Python Coding
  • Send Message View Discussions
Hello...
你好,

Is there any way I can access the name a user puts onto a component (via thecontext menu), and use that at runtime?
有什么方法在用户自定义组件运行时,我可以访问这个组件的名字(通过上下文菜单)?
This would be a compiled component.
这将是一个编译的组件
Lets say that the input is a string "hello" and the user changes thename of the component to "hello."
就像这样,输入一个字符串“hello”然后用户就就把组件的名字改为了“hello”
Can I test if the input string and the nameare the same in order to condition the output?
我可以在它们输入字符串和名称这样相同的条件下,测试它们的输出吗?
Thanks!
谢谢
Luis
Luis
Tags:
ShareTwitterFacebookFacebook
Views: 991
Permalink Reply by Luis Fraguada on June 22, 2010 at 3:33pm
Hello-to],
你好,

Interesting, not at all the place I was looking for it. Now, this is a systemnamespace...I would have guessed this was more a GH_* thing? Ok, well, lets seewhere this leads! Thanks man!
非常有趣,这不是我提出问题所在点。现在,这是一个系统名称空间,我想我猜到了这是GH的事情了?好吧,让我们看到了哪些地方导致的,谢谢,
luis
luis
Permalink Reply by Luis Fraguada on June 23, 2010 at 4:04am
maybe sthmore like this...
也许某些事情更像这个:
public delegate void GH_MenuTextBoxTextChanged(
GH_MenuTextBoxCollection sender,
string iText
)
Permalink Reply by David Rutten on June 23, 2010 at 4:56am
Hi Luis,
你好,Luis

the "name" of an object that the user can change is actually calledNickName inside the SDK.
用户改变对象的名字,实际上只不过是在SDK中称之为“昵称”而已。

All objects on the canvas have the following memberswhich are implemented from IGH_InstanceDescription:
所有的canvas对象以下属性是从IGH_InstanceDescription中实现的。
- Name (official name)
-名称(官方名字)
- NickName (name displayed in UI, changeable by user)
-昵称(在UI上显示的名字,用户可以更改的。)
- Description (brief explanation of what the object does, visible in Tooltips)
-说明书(简要的介绍该对象的作用)
- Category (name of the tab that contains the object)
-分类(该对象所属某类)
- SubCategory (name of the panel that contains the object)
-子分类(该对象所属父类中某一子类)
There's a bunch more, but these are the most important ones.
还有很多属性,但是这些是最重要的,

When you're inside a VB or C# script, there is a member variable called ownerof type:
当你在VB或者C#的脚本里,有一个叫做“所有者”的类型也是类型中的一种:
Grasshopper.Kernel.IGH_ActiveObject

IGH_ActiveObject derives from IGH_InstanceDescription, so the NickName of thecomponent itself should be available as follows:
因为IGH_ActiveObject来源于IGH_InstanceDescription,所以组件本身的昵称可以像下面一样定义。
Dim nn As String = owner.NickName


If however you want the nicknames of input parameters, then you have to castthe owner object to a GH_Component.
但是,如果你想要改变昵称作为输入参数,你就必须把所有的用户对象转换为GH的组件。
GH_ActiveObject is lower in the inheritance hierarchy andit doesn't know about input and output parameters.
GH_ActiveObject的继承优先级比较低,并且它没有输出和输入参数这一说法。
So, in order to get the nickname of the first inputparameter, do:
所以,为了得到第一个输入参数的昵称,应该这样做:
Dim cmp As GH_Component = DirectCast(owner, GH_Component)
Dim nn0 As String = cmp.Params.Input(0).NickName


There are events that are raised whenever nicknames change, but I don'tthink you want to go in that direction.
有方法能够改变昵称,但是我认为不是你想的那个方向。
At any rate, system.ComponentModel.Design.ComponentRenameEventHandler doesn'thave anything to do with Grasshopper Components.
无论如何,这个system.ComponentModel.Design.ComponentRenameEventHandler跟GH组件没有一点关系都没有。
--
David Rutten
david@mcneel.com
Turku, Finland
Permalink Reply by Luis Fraguada on June 23, 2010 at 6:23am
HelloDavid,
你好,David
That is excellent! The nickname is exactly what I was looking for.
这个非常好,这就是我所要寻找的昵称。
Tested it out on a vb component and it seemsto be functioning very well.
我测试了一个VB组件,而且它运行非常好。
I was thinking of this for incoming OSCMessages...
我想着这传入了OSC信息
a usercould change the Nickname of the component to the name of the device...
用户能够改变组件图案的昵称。。。。
if thename of the device from the incoming message matches the nickname, then thatdata is stored...
如果组件图案的名字的



Are there any extra considerations when compiling a component with this infoyou have provided?
当你编译一个组件使用此信息时,有其他考虑吗?

I could imaginethat I would need to set up what the active object is?
我能够想象,我不知道我设置的活动对象是什么。
Permalink Reply by Luis Fraguada on June 23, 2010 at 9:35am
For futurereference. I was able to get the nickname of the component instance from thebase...
仅供参考,我可以从这些基础的得到组件的昵称
in a C# project (_nn is a string):
在一个C#组件里(nn是个字符串名)

_nn = base.NickName;


Any hints on adding the functionality of a wifi/receiver input?
在任何提示下,能够添加一个wifi/接收器的输入端吗?
Permalink Reply by  on June 23, 2010 at 10:46am
hi luis
你好,luis

maybe this time i am right ;)
也许这一次我是对的,
reflect GH_Receiver (Grasshopper.Kernel.Parameters.GH_Receiver)
反映GH_Receiver(Grasshopper.Kernel.Parameters.GH_Receiver)

Permalink Reply by Luis Fraguada on June 23, 2010 at 11:14am
to],

I was checking out the receiver component where you specified and it derivesfrom something other than GH_Component...
我检查了你所指组件具有接收器功能的组件,他是来源于GH_Component.之外的东西。
in thiscase GH_Param. So I would be assuming that I would need to construct it verysimilarly to this...but I think I would be assuming too much.
对于在这种情况下的GH_Param,我假定我需要构造非常类似于。。。但是我认为我想的太多。
David, could we get that functionality in GH_Component (if it does not alreadyexist through overriding)?
David,我们能够在GH_Component中我们能实现这种功能吗(在不通过覆盖已经存在的功能的情况下)?
Permalink Reply by David Rutten on June 24, 2010 at 6:48am
True, the Receiver object derives from GH_Param. You cancast objects to parameters in the same way as you'd cast objects to components:
对,对象接收器来源于GH_Param.,你可以把对象参数的方法应用于对象组件中。
Dim param As IGH_Param = DirectCast(someobjectyouknowforsureisaparameter, IGH_Param)


IGH_Param is a fairly simple object type. GH_Component is much more complex asit contains the component logic plus any (variable) number of input and outputparameters.
IGH_Param是个非常简单的对象类型。GH_Component要复杂的多,应为他包含了组件之间的逻辑关系还有(变量)输入和输出的数量。
Most special objects in Grasshopper derive from IGH_Param (TextPanel,GraphMapper, ParamViewer, BarGraph, Slider etc., notable exceptions beingGradient, Legend, Timer and Scribble which are just basically weird).
Gh中最特殊的对象都是来源于IGH_Param(想这些组件TextPanel, GraphMapper, ParamViewer, BarGraph, Slider 等等,明细的例外是Gradient, Legend, Timer and Scribble这些非常奇怪。)

The Receiver object is nothing more than a Generic Parameter with an overriddendisplay function.
具有接收器功能对象只不过是一个普通的参数覆盖了显示功能而已。
--
David Rutten
david@mcneel.com
Turku, Finland
Permalink Reply by Odysseas Georgiou on February 2, 2011 at 3:06am
Hello, 3
你好
is itpossible to inherit the NickName of a param plugged in a custom component then?
在继承参数时,可以插入一个自定义昵称的组件吗?
Do I still have to cast the input parameterwhere the param is plugged into and then cast it to an IGH_Param or am i justtalking nonsense?
我能够操作一个插入进来的参数,然后把这个参数放进IGH_Param里吗,或者我根本就在说废话?
Thanks,
谢谢
Odysseas
Permalink Reply by Dirk Anderson on January 16, 2012 at 10:14pm
To get thenames of the input components nickname:
‘得到能够输入组件的的昵称:
'accessthe vb component
访问VB组件,
Dim cmp AsGH_Component = DirectCast(owner, GH_Component)
'accessthe first parameter input of VB component
‘访问VB组件的第一个参数
Dimparam_0 As IGH_Param = DirectCast(cmp.Params.Input(0), IGH_Param)
'accessthe list of input components
‘访问输入组件的输入列表
DimighList As List (Of IGH_Param) = param_0.Sources
Dim inParam_0 As IGH_Param = DirectCast(ighList(0), IGH_Param)
'printsthe nickName of the first input component
‘输出第一个组件的昵称。
Print(inParam_0.NickName)
Permalink Reply by David Rutten on January 17, 2012 at 2:45am
Hi Dirk,
你好,Dirk
sorry, isthere a question? You don't need this btw:
对不起,还有问题吗?你不需要再解释一下:
Dimparam_0 As IGH_Param = DirectCast(cmp.Params.Input(0), IGH_Param)

Params.Inputis already a collection IGH_Param, so you don't have to cast them:
Params.Input本来已经是IGH_Param的成员,所以你不需要操作它们:
Dimparam_0 As IGH_Param = cmp.Params.Input(0)

--
DavidRutten
david@mcneel.com
Poprad, Slovakia
GlamDoGetAdsDone();png?width=48&height=48&crop=1%3A1"alt="" />Permalink Reply by David Rutten on January 17, 2012 at 2:46am
In asimilar vein, Sources is also already a collection of IGH_Param, so no castingrequired there either:
同样,Sources也是IGH_Param的成员,所以同样不需要操作它们:
DimighList As List (Of IGH_Param) = param_0.Sources
Dim inParam_0 As IGH_Param =ighList(0)

--
David Rutten
david@mcneel.com
Poprad,Slovakia
Permalink Reply by Dirk Anderson on January 17, 2012 at 4:01pm
thanksDavid - totally overlooked the unnecessary code.
谢谢David,忽略了完全不需要的代码
Permalink Reply by erik l on June 18, 2012 at 10:57am
First off,thanks for those who contribute, there is much to learn in these posts.
首先,感谢那些做出贡献的人,这里有许多值得我们学习的地方。
I haveworked in GH but am branching into VB scripting now to expand my definitions.
我曾经痴迷于GH,现在它的分支VB脚本再次开拓了我的视野。
Thefunction described here is exactly what I want to accomplish but I am notcertain how this would done in the VB script component..
这里所描述的功能正是我所需要的,但是我不知道怎么用VB脚本去实现这个功能。
Is this something done via a custom component?
这是通过一个自定义组件的东西吗?
Basically, if someone could provide me some guidanceas to which direction to start, I will be happy to try from there.
如果有人能够提供一些指导,指引我,我很高兴去学习它。
Thanks
谢谢
Erik
Erik

Permalink Reply by erik l on June 20, 2012 at 11:26am
Alright, Ihave been trying this now for a few days.
好吧,现在我已经开始学习几天了。
I was notsuccessful in creating this either as a custom script component or building acustom component in VB.
我没有成功地创建这个自定义脚本或者用VB构建一个自定义组件。
Can anyone possibly provide a example VBexample?
是否有人能够提供一个用VB构建一个组件的例子吗?
I have visual studio and can compile my owncomponent but I am at a loss.
我有visualstudio并且编译了自己的组件,但是我感觉不对。
I wish I understood more about creating thesebut having an example to build from would move me ahead.
我希望了解更多这方面的例子,来完善我以前的例子。
Thanksagain.
再次感谢。
Permalink Reply by David Rutten on June 20, 2012 at 12:36pm
Whatexactly are you trying to accomplish?
你真正的想做什么呢?
Do you want to use the nickname of the VBscript component inside the RunScript method?
你用内置的RunScript的方法来编译VB脚本组件的昵称?
Do you want to recompute the script componentwhen the name changes? Or...?
--你想更改组件的名字?还是?
DavidRutten
david@mcneel.com
Poprad,Slovakia
Permalink Reply by erik l on June 20, 2012 at 1:58pm
I washoping to to pull the nickname from an attached element then feed this to anoutput from the VB script component.
我想把组件的昵称作为一个因素,并且VB脚本组件中可以输出
The hopeis to combine this with other functions later but for now this would be a goodstart.
希望能跟其他功能结合起来,但现在只想有个好的开头。
An example would be if you had a list of 10 sliders with custom nicknames,named for specific functions.
例如,如果你有10个滑块的列表因功能不同而定义了不同的昵称。
You couldthen feed the sliders into the VB component which could take the nicknames andthe values and compile them to feed to an excel dataspreadsheet.
你可以这些滑块与这个VB组件连接,然后得到它们的昵称,值形成的一个excel数据表格。
This ismore the final goal but at a good start would be to at least pull the nicknamesof the sliders for example.
这是高级目标,但现在至少有一个好的开始时以滑块的昵称为例。
I am attaching an image with a small pseudo-example of what it might look like.
下面是我的一张截图,应该基本可以表达了我的意思。
Thanks
谢谢
Attachments:
See attached. File contains some notes andthe code is commented.
--请看附件,包含了一些笔记和注释代码。
DavidRutten
david@mcneel.com
Poprad,Slovakia
Attachments:
§  GetSourceNickName.gh, 2 KB
VB,code::
Private Sub RunScript(ByVal x As Object, ByVal y As Object, ByRef A As Object)
    'First we need to get at the first input parameter of thescript component.
    'Since the script component may have any number ofinputs, we should be careful
    'to test that there's at least one.
    '1. Cast the 'owner' instance to an IGH_Component
    Dim component As IGH_Component = TryCast(Owner, IGH_Component)
    If (component Is Nothing) Then
        Print("This shouldnever have happened, but the owner of this script is not a component.")
        Return
    End If

    '2. Test for at least a single input parameter.
    If (component.Params.Input.Count = 0) Then
        Print("The scriptcomponent needs at least a single input parameter.")
        Return
    End If

    '3. Get the first input parameter, and collect all sourcenicknames in a list.
    Dim param As IGH_Param = component.Params.Input(0)
    Dim names As New List(Of String)
    For Each source As IGH_Param In param.Sources
        names.Add(source.NickName)
    Next

    '4. Create a single string from all the source nicknames.
    Dim tag As String = String.Join(", ", names.ToArray())

    '5. Assign the tag to the output A.
    A = tag
End Sub
Permalink Reply by erik l on June 20, 2012 at 4:10pm
David,
Thank you,this is very helpful.
谢谢你,这个对我非常有帮助
As thisprogresses I will try to post an example of the tool under a new posting.
我将试着将这个方案变为一个新的工具发布
Permalink Reply by phillip on March 12, 2013 at 12:05pm
Sorry formy knowledge being so weak, but how do ichange your
抱歉,虽然在下不才,但是我还是更改一下你代码:
Dim paramAs IGH_Param = component.Params.Input(0)
Dim names As New List(OfString)
For Each source As IGH_ParamIn param.Sources
names.Add(source.NickName)
Next
to recievejust a list in the same tree structure as the input?
接收在同一个列表树结构作为输入?
Permalink Reply by David Rutten on March 12, 2013 at 2:28pm
I don'tunderstand. What list? What tree structure? Which input?
--我没明白,什么列表?什么树结构?什么输入?
DavidRutten
david@mcneel.com
Poprad,Slovakia
Permalink Reply by phillip on March 13, 2013 at 4:37am
I justwant to recieve the Nickname of the source without any Join String or repeatingList.
我仅仅是接收没有任何连接字符串的昵称或者重复列表。
Permalink Reply by David Rutten on March 13, 2013 at 5:29am
Theremight be more than one source
可能有多个来源。
. Ifthere's more than one then which should it be?
如果不止一个,那该怎么办?
If thereare no sources then what should happen?
--如果没有输入了,又该怎么办呢?
DavidRutten
david@mcneel.com
Poprad,Slovakia
Permalink Reply by phillip on March 13, 2013 at 6:42am
Just asyou wrote it, I guess:
根据你写的代码,我想:
Dimcomponent As IGH_Component = TryCast(owner, IGH_Component)
If (component Is Nothing)Then
Print("This shouldnever have happened, but the owner of this script is not a component.")
Return
End If

If(component.Params.Input.Count = 0) Then
Print("The scriptcomponent needs at least a single input parameter.")
Return
End If
The thingI am not getting is , how to recieve them all afterwards. I tried
得不到我想要的,如何去接收它们,我尝试:
Dim paramAs IGH_Param = component.Params.Input(0)
DimighList As List (Of IGH_Param) = param.Sources
Dim inParam As IGH_Param =ighList(0)
Dim namesAs String = inParam.nickname
A = names
But thisjust returns (0) of ighList.
但这只是返回(0) of ighList.

Do I haveto reference all items by index?
我要参考所有项目的索引?
Missingsome basics here.
在这里缺少一些基本知识。
Permalink Reply by phillip on March 14, 2013 at 4:02pm
Cansomebody give me a hint please?
有人能我一些提示吗?
Permalink Reply by David Rutten on March 14, 2013 at 6:00pm
If youwant to output all the names of all the sources of the first input parameter,you'll need to create a list:
如果你想输出在第一个输入参数输入名字的来源,你需要创建一个列表:
Dim namesAs New List(Of String)
For Eachsource As IGH_Param in component.Params.Input(0).Sources
names.Add(source.NickName)
Next
A = names
--
DavidRutten
david@mcneel.com
Poprad,Slovakia
Permalink Reply by phillip on March 15, 2013 at 3:12am
Its notreally what I am trying to achieve.
它不是我希望的结果
I think Ihave to be more clear.
我认为它应该更清晰。
See, thisis what I want:
看,下面就是我想要的。

This iswhat I meant with same treestructure as the input.
我的意思是与输入的树结构式一样的
How isthis possible?
这怎么可能?
Attachments:
§  SourceNameQuestion.gh, 3 KB
Vbcode::
Private Sub RunScript(ByVal x As Object, ByVal y As Object, ByRef A As Object)
    'First we need to get at the first input parameter of thescript component.
    'Since the script component may have any number ofinputs, we should be careful
    'to test that there's at least one.
    '1. Cast the 'owner' instance to an IGH_Component
    Dim component As IGH_Component = TryCast(Owner, IGH_Component)
    If (component Is Nothing) Then
        Print("This shouldnever have happened, but the owner of this script is not a component.")
        Return
    End If

    '2. Test for at least a single input parameter.
    If (component.Params.Input.Count = 0) Then
        Print("The scriptcomponent needs at least a single input parameter.")
        Return
    End If

    '3. Get the first input parameter, and collect all sourcenicknames in a list.



    Dim names As New List(Of String)
    For Each source As IGH_Param In component.Params.Input(0).Sources
        names.Add(source.NickName)
    Next

    A = names


End Sub
Permalink Reply by David Rutten on March 15, 2013 at 6:35am
You'llneed to make a DataTree<string> to store your data in.
你需要做一个DataTree<string>来储存你的数据。
Thefollowing code is untested, but I think it probably works:
下面的代码还没经过测试,但我相信它能够运行:
DataTree<string> names = newDataTree<string>();
IGH_Param input = Params.Input[0];
foreach (IGH_Param source in input.Sources)
{
string name = source.NickName;
IGH_Structure data = source.VolatileData;
foreach (GH_Path path in data.Paths)
{
names.Add(name, path);
}
}
A = names;
ps. Irealizes you're using VB, you can use this page to convert the code.
附注:我意识到你正在使用VB,您可以使用此页面转换代码。
--
DavidRutten
david@mcneel.com
Poprad,Slovakia
Permalink Reply by phillip on March 15, 2013 at 6:55am
Thank you!
谢谢
p.s.:great page - didn´t know that , thank you again.
附注:好的页面,但是我不知道怎么转换,再次感谢。
Permalink Reply by roderick read on March 26, 2013 at 8:09am
I havetried to reconfigure the VB in this example so that I can output data to excelthrough tttoolbox.
在这个例子中,我尝试重新配置VB,这样我可以通过tttoolbox.把输出的数据转换到Excel中,
no luck...I'm not very grammatically / script gifted.
不幸的是,我在语法/脚本上我不是天才。
I havelines with nicknames ... sometimes a single line sometimes a list of lines..
我有一行昵称,但是有时候是单行,有时候是列表
I want topass the nickname and line length data of each line to tttoolbox...
我把昵称和每一行数据长度匹配到tttoolbox.
Like theentwine data component... but also passing on the nickname data.
就像这个entwine数据组件一样,但也传递昵称这一数据。
Any ideas?
有办法吗?

Permalink Reply by roderick read on March 26, 2013 at 3:14pm
What I amtrying, is to get a list of each input component with it's nickName and valueoutput as a list instead of as an array.
我尝试把每个输入组件的列表与它的昵称和值输出为列表而不是一个数组。
I hope I'mmaking sense.
我希望我是对的。
Permalink Reply by roderick read on March 29, 2013 at 9:04am
Actually,All I needed was a simple list out of each nickname connected to the x input.
实际上,所有我需要的是一个简单的列出每个昵称连接到x输入。

So I got(nearly) that by removing step 4 "creating the tag string.
所以我通过删除步骤4“创建标记字符串
"then I set a to only output the names....
然后我设置了输出名称
'3. Getthe first input parameter, and collect all source nicknames in a list.
获得第一个输入参数,并收集所有源列表中的昵称。

Dim param As IGH_Param = component.Params.Input(0)
Dim names As New List(Of String)
For Each source As IGH_Param In param.Sources
names.add(source.NickName)
Next

'5. Assign the tag to the output A.
A = names
This stillgives me too much output but I can clean it up in grasshopper.
在gh里这给了很多的输出,但是我可以清除一部分。
Using tree branch and path {0;0} and takingthe result into the rows input of tttoolbox
用树枝和路径{ 0,0 },在tttoolbox行中得到输入的结果
... aslong as I connect my lines in the same order to the entwine and the VB script Ican get a nice output
就像我联想到entwine组件一样,在VB脚本中能够得到很到的输出
ok it'snot ideal but it works for me just now...
虽然现在不是理想的情况,但我可以利用它来工作了。
I'll haveto put comment on the .gh definition to make it clearer
我希望GH的定义把它搞的更清除。

Thanksguys
谢谢小伙
精彩分享:
欢迎传播此微信号:SecondEffectGroup
外链图片
设为封片

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

精彩回复

文明上网理性发言、请文明用语

siyecao21033 | 设计助理 | 发表于 2015-5-19 14:50:08
杰哥 哈哈
0 回复

举报