Question custom components

Why is it that in all examples in the forums (old and new) people create new guid isn’t it always new when the component is placed on the canvas?

Do you mean the components GUID that is set in the visual studio creation of a component?

The Guid you define when making a VS component permanently indentifies the component’s “type” so to speak. This way the component always stays the same (from the computer’s perspective) even if you have multiple copies (instances) of the same type of component on the canvas.

However, the component instances on the canvas also has another guid - the instance guid (or “ObjectId”) so that different copies (instances) can be kept apart (considered unique) on the canvas. But these object copies can still be indentified as being of exactly the same type (same name and same function).

In programming terms this is the difference between a Class (type) and multiple instantiated Objects of that Class. Which could be said to be the drawing (“class”) and the houses (object instances) build according to the drawing. The drawing for the same kind of houses would always have the same id (or Guid) while the different built houses would have unique id’s (addresses or whatever).

BTW, this seems to be a problem with UserObjects - saving an updated version means editing an instance, “a new house”, which then gets a new Guid when overwriting the old one, which means that old instances in GH definitions are not being updated. (disclaimer on UserObjects specifically - I might just not know how to update the UserObjects properly, but if so, hopefully someone can inform me what I’m missing)

// Rolf Lampa

Edit: Example: If you put one Division components on the canvas and select it and copy (CTRL-C) and paste the xml info into a text editor (CTRL-V), you will find that both components shares one guid (they have the same “< GUID >”, search for this one: 9c85271f-89fa-4e9f-9f4a-d75802120ccc) but they have different < InstanceGuid >'s, like so:

    <item name="GUID" type_name="gh_guid" type_code="9">9c85271f-89fa-4e9f-9f4a-d75802120ccc</item>
    <item name="Name" type_name="gh_string" type_code="10">Division</item>
    ...
    <chunk name="Container">
     ...
        <item name="Description" type_name="gh_string" type_code="10">Mathematical division</item>
        <item name="InstanceGuid" type_name="gh_guid" type_code="9">47cb75d5-3650-4035-ba1e-210d973fc188</item>
        <item name="Name" type_name="gh_string" type_code="10">Division</item>

Here another copy of the same Division component:

    <item name="GUID" type_name="gh_guid" type_code="9">9c85271f-89fa-4e9f-9f4a-d75802120ccc</item>
    <item name="Name" type_name="gh_string" type_code="10">Division</item>
    ...
    <chunk name="Container">
        ...
        <item name="Description" type_name="gh_string" type_code="10">Mathematical division</item>
        <item name="InstanceGuid" type_name="gh_guid" type_code="9">dccaad15-8cef-4e25-a6c6-21db8f687418</item>
        <item name="Name" type_name="gh_string" type_code="10">Division</item>
3 Likes

Oh so there are two GUIDs, now it makes sence,

Thanks a lot for explanation Rolf.

    public override System.Guid ComponentGuid
{
  get { return new Guid("{4D2A3993-62AD-4161-8FEB-E08252ED70C0}"); }
}

So in the above snippet a new exact value of the GUID is set to that class, but how do you ensure that this value is unique?

Whenever you create a guid using a tool (like VS Tools | Create Guid) you will get a… well, “Globally Unique ID” (guid), which really is globally unique. There’s more combinations in those guids than there are electron’s in the universe. Kind of. Virtually no chance for conflict.

But if you “hand craft” a guid it’s not going to be very unique. At best a puid (personally unique id… :slight_smile: )

// Rolf

That is unlikely. I assume it’s random generated, there are millions using VS they have upto a thousand apps with thousands of classes, and there’s no connection between all VS copies that are started to ensure unique generation. Variations on the string this size could be only a few billion.

Anyways, I was asking how can I set (pick) proper guid when creating a ghpython compiled component, and what happens if by chance it matches one of the components already installed in GH from some plugin?

Hm. Consider this:

(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position) *
(Number of letters (ABCDEF) + the number of digits (0123456789) in each position)

= so big a number that you cannot say it. :slight_smile: ("a number of “billion billions” is only a tiny fraction of such big a number.

Edit: Example of usage. When I designed a transport logistics system I tagged every booking/parcel with a Guid making it possible to exchange data (bookings) between different independent installations of the system (like regional logistics centras, or in fact, between any logistics central on earth) and one can then assume that, if exchanging parcels/bookings between the systems, an id-conflict will never happen, at least not once in a “gazillion” years of time.

// Rolf

Yes, I know the math, I said it likely. Neverhteless, no matter how high the number is if there’s no algorithm to store already created GUIDs and remove them from the “pool” of all variations a match could happen. You know, like drawing cards from a deck. If you draw 5 cards and reshuffle the deck then out of the 52 cards you draw 5 cards, there’s always a chance you draw 5 identical cards in the same order. But if you draw 5 cards, then remove them from the deck you can ensure this combination never appears.

Pick an electron from anywhere in the universe, from any planet or star, and then pick another electron from anywhere in the universe, from any planet or star, and then sit down an worry about the risk that you got exactly the same two electron’s…

Knowing the digit’s is not the same thing as knowing the math it represents… :wink:

// Rolf

Humor me, what will happen if two components in GH happen to have matching GIUDs?

I wouldn’t worry. I really wouldn’t. But IF it ever happened, I’d celebrate big time! :champagne::cocktail::sparkler::tada::balloon::boom::dizzy::man_dancing: !!!

I’d invite all from McNeel to join in.

// Rolf

(Pst: And you too! :slight_smile: )

2 Likes

:smiley:

Practically if two components have the same ID, GH will raise a version conflict upon loading and ask which version it is supposed to load. But you can test this yourself by copy-pasting the same guid in different components.

On the theoretical side there are hundreds of stackoverflow threads and a huge wikipedia article on the probabilities of collision…

You will get an error message about the conflict and they won’t load. Happened to me before when I copy/pasted one code to another and forgot to regenerate the new GUID. Similar to if you update a component without obsoleting it and then open a definition that had an old version of the component with the same GUID.

For the lazy ones:

Michael, how can I obsolete it?

:smiley: @jesterking, I love such articles in wikipedia when talking about probability and then they say:

Thus, for there to be a one in a billion chance of duplication, 103 trillion version 4 UUIDs must be generated.

When talking about probability only 1 might be necessary to get a collision, it’s just that this might is very very small chance.

Name the class with _OBSOLETE

So something like

public class Component_ConstructPoint : GH_Component

would become

public class Component_ConstructPoint_OBSOLETE : GH_Component

That will make it have the “old” tag written over the component icon

Then set its exposure to hidden so it only comes up when searching with #
You can find all GH old components by searching with # so for instance in this case you can search #ConstructPoint to still get access to it in gh.

For that you do:

public override GH_Exposure Exposure
{
get
{
return GH_Exposure.hidden;
}
}

5 Likes

Thanks a lot Michael.

I use this: https://www.guidgenerator.com/

1 Like

Another way is to assign the [Obsolete] attribute to the class. A bit more official, but I actually prefer to change the name since it’s instantly obvious even when looking at a list of class names which ones are obsolete.

2 Likes