Transfer Project Standards Revit API

Transfer Project Standards Revit API

Anonymous
Not applicable
5,940 Views
10 Replies
Message 1 of 11

Transfer Project Standards Revit API

Anonymous
Not applicable

I would like to transfer project standards through Revit API. I am able to copy all the elements except shared parameters. Please let me know how can I copy the shared parameters while doing transfer project standards.

 

Any help would be appreciated.

 

0 Likes
Accepted solutions (1)
5,941 Views
10 Replies
Replies (10)
Message 2 of 11

matthew_taylor
Advisor
Advisor
Accepted solution

Hi,
Have you checked out the overload of CopyElements that allows copy-pasting between documents?
http://www.revitapidocs.com/2017/b22df8f6-3fa3-e177-ffa5-ba6c639fb3dc.htm
It should do that.
[Edit]p.s. There's an example in the SDK.[/Edit]


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 3 of 11

Anonymous
Not applicable

I tried using CopyElements(). But it doesn't work. It throws an error stating - 

 

"Some of the elements cannot be copied, because they are view-specific.\r\nParameter name: elementsToCopy:"

0 Likes
Message 4 of 11

matthew_taylor
Advisor
Advisor
I would suggest posting code so that it can be checked.

Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 5 of 11

Anonymous
Not applicable

Please find below the code.

 

transaction.Start();
FilteredElementCollector wallTypesProject = new FilteredElementCollector(doc).OfClass(typeof(WallType));
foreach (WallType wtcur in wallTypesProject)
{
ICollection<ElementId> copyIds = new Collection<ElementId>() { wtcur.Id };
CopyPasteOptions option = new CopyPasteOptions();
ElementTransformUtils.CopyElements(docSource, copyIds, docTarget, Transform.Identity, option);
}
transaction.Commit();

0 Likes
Message 6 of 11

matthew_taylor
Advisor
Advisor
Hi,
Is doc the same as docsource? Otherwise it looks okay. Are you sure the wall type doesn't exist in the target document?
Also, you mentioned copying shared parameters, but your code does not.
Are you talking about shared project parameters on the Wall category, or something else?
You need to be more clear about the question, and include code that allows us to run your sample (or at least shows all declarations).


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 7 of 11

Anonymous
Not applicable

Clarification to my Question : I have a document called docSource. The document has all the built in parameters and we added a shared parameter to it. Now, I am trying to do transfer project standards, I am trying to copy/duplicate all walltypes to the target project which is my project. So, I am duplicating the wall types from docSource to docTarget. When I am copying all the parameters, only the particular shared parameter which we have added to docSource is not duplicating/Copying. Everything else is getting duplicated except the shared parameter we have added. I am using the below code.

 

 

 

public void TransferProjectStandards(ModelPath fileName, Document doc, Application App)
{
OpenOptions openOption = new OpenOptions();
openOption.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets;
Document docFamily = App.OpenDocumentFile(fileName, openOption);
FilteredElementCollector wallTypes = new FilteredElementCollector(docFamily).OfClass(typeof(WallType));

WallType wallType = null;

foreach (WallType wt in wallTypes)
{
wallType = wt;
if (!CheckWallTypeExists(wt, doc))
{
using (Transaction t = new Transaction(doc))
{
t.Start("Transfer Wall Type");
WallType newWallType = null;

FilteredElementCollector wallTypesProject = new FilteredElementCollector(doc).OfClass(typeof(WallType));

foreach (WallType wtcur in wallTypesProject)
{
if (wtcur.Kind == wallType.Kind)
{
newWallType = wtcur.Duplicate(wallType.Name) as WallType;
break;
}
}
Parameter p = null;
foreach (Parameter p1 in newWallType.Parameters)
{
Definition d = p1.Definition;

if (p1.IsReadOnly)
{
break;
}
else
{
p = wallType.get_Parameter(d);

if (null == p)
{
break;
}
else
{
if (p.StorageType == StorageType.ElementId)
{
break;
}
else
{
if (p.StorageType == StorageType.Double)
{
p1.Set(p.AsDouble());
}
else if (p.StorageType == StorageType.String)
{
p1.Set(p.AsString());
}
else if (p.StorageType == StorageType.Integer)
{
p1.Set(p.AsInteger());
}

}
}
}
}

t.Commit();
}
}
}
}

 

0 Likes
Message 8 of 11

matthew_taylor
Advisor
Advisor

@Anonymous,

After testing this using the UI, I would suggest trying to copy the relevant SharedParameterElement via the CopyElements fromView/ToView overload (prior to copying the wallTypes).

You may want to test using a fixed element ID.

 

Let us know how you get on.

 

Cheers,

 

-Matt


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 9 of 11

FAIR59
Advisor
Advisor

@Anonymous

 

you are not really copying the walltypes, but are recreating them in the target document. As Matthew suggested in a earlier post, copying them using the

ElementTransformUtils.CopyElements() method might be a better option, it might even copy the shared parameter along.

 

0 Likes
Message 10 of 11

Anonymous
Not applicable

Thanks. CopyElements did work for me. It copied all the builtin parameters from source wallType to target walltype except the shared parameter. I was able to write an API which would copy all the shared parameters to the target wallType. 

 

Thanks so much for your help!

0 Likes
Message 11 of 11

Anonymous
Not applicable

@Anonymous - It seems that when using CopyElements method to copy a WallType from one document to another if a WallType already exist with the same name the following message appears "Type has been renamed to avoid conflicts with existing element". Have you managed to transfer a WallType by overriding the existing one? 

 

Type has been renamed to avoid conflicts with existing element..jpg

0 Likes