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.
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.
Solved! Go to 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]
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:"
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();
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();
}
}
}
}
@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
@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.
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!
@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?