Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Transfer Project Standards Revit API

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
Anonymous
5096 Views, 10 Replies

Transfer Project Standards Revit API

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.

 

Tags (1)
10 REPLIES 10
Message 2 of 11
matthew_taylor
in reply to: Anonymous

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?
Message 3 of 11
Anonymous
in reply to: matthew_taylor

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:"

Tags (1)
Message 4 of 11
matthew_taylor
in reply to: Anonymous

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?
Message 5 of 11
Anonymous
in reply to: matthew_taylor

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();

Tags (1)
Message 6 of 11
matthew_taylor
in reply to: Anonymous

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?
Message 7 of 11
Anonymous
in reply to: matthew_taylor

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();
}
}
}
}

 

Message 8 of 11
matthew_taylor
in reply to: Anonymous

@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?
Message 9 of 11
FAIR59
in reply to: matthew_taylor

@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.

 

Message 10 of 11
Anonymous
in reply to: FAIR59

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!

Message 11 of 11
Anonymous
in reply to: FAIR59

@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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report