Copy-Paste objects include ElementId

Copy-Paste objects include ElementId

Anonymous
Not applicable
1,967 Views
3 Replies
Message 1 of 4

Copy-Paste objects include ElementId

Anonymous
Not applicable

Hi I am copying Elements from a linked File

using:

ElementTransformUtils.CopyElements(Sourcedoc, Li_SelectedId, doc, null, CP_options);

 

I want to include the elementId from en "SourceObject" into the new Object, eg in a special parameter or ???

Is it possible and how ?

 

Regards

0 Likes
Accepted solutions (1)
1,968 Views
3 Replies
Replies (3)
Message 2 of 4

BardiaJahan
Advocate
Advocate

I believe, to assign the LinkedElementId to the copied element, you have to copy elements one by one. 

And yes of course you can assign the ElementId of the linked element to any parameter of the copied element. Something like this, e.g.:

 

 

ICollection<ElementId> copiedElementIds = ElementTransformUtils.CopyElements(Sourcedoc, Li_SelectedId, doc, null, CP_options);

doc.Regenerate();
ElementId copiedElementId = copiedElementIds.FirstOrDefault();
Element copiedElement = doc.GetElement(copiedElementId);
Element.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).SetValueString(Li_SelectedId.ToString());

 

 

0 Likes
Message 3 of 4

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Anders,

 

Thank you for your query, and many thanks to Bardia for his answer.

 

I almost completely agree with it.

 

Personally, I would use the Parameter.Set method overload taking a string argument instead of SetValueString, cf. the recent discussions on SetValueString and the difference between that and Set(string):

 

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 4 of 4

Anonymous
Not applicable

Thanks

I made it Work with small modifikation:

 

foreach (Element ActDoor in FEC_SourceDoors)

{

        Li_SelectedId.Add(ActDoor.Id);

     ICollection<ElementId> copiedElementIds = ElementTransformUtils.CopyElements(Sourcedoc, Li_SelectedId, doc, null,

     CP_options);

        ElementId copiedElementId = copiedElementIds.FirstOrDefault();

        Element copiedElement = doc.GetElement(copiedElementId);

        copiedElement.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set

        (Li_SelectedId.FirstOrDefault().ToString());

        Li_SelectedId.Clear();

}

 

0 Likes