Quantcast
Channel: All Revit API Forum posts
Viewing all articles
Browse latest Browse all 66683

How to add material to family symbols through .NET API?

$
0
0

Hi,

I try to set material to family symbols through .NET API.

Is there a simple way to set material to FamilyInstance or Symbo?

I´m not yet familiar with Family API with materials so this may be a frustrating question.

FamilyInstanceProperties.jpg

What I´m going to do is described below.

1. Load multible rfa -files to one family template rfa -file.

2. Insert one familysymbol from each rfa -file to main family template rfa -file.

3. Set different materials to each family symbols in main family template file. (I don´t know is this possible)

4. Save main rfa -file.

 

Cheers

Veli V.

 

Example try out code below.

Using famItemCreator As Autodesk.Revit.Creation.FamilyItemFactory = doc.FamilyCreate
                    For Each mfpItem As MartelaFamilyParam In colMartelaFamilyParams
                        If Not doc.LoadFamily(mfpItem.rfaFile, fam) Then Continue For
                        If fam Is Nothing Then Continue For

                        familySymbolIds = CType(fam.GetFamilySymbolIds, System.Collections.Generic.ISet(Of ElementId))
                        If familySymbolIds Is Nothing Then Continue For
                        If familySymbolIds.Count > 0 Then
                            If familySymbolIds.Count > 1 Then
                                DisplayRevitMessage("Family " + fam.Name + " have more that 1 symbols.", "We add the first one: " + doc.GetElement(familySymbolIds(0)).Name)
                            End If
                            fs = CType(doc.GetElement(familySymbolIds(0)), FamilySymbol)
                            If Not fs.IsActive Then fs.Activate() : doc.Regenerate()
                            If Not fs Is Nothing Then
                                famInstance = famItemCreator.NewFamilyInstance(New XYZ(mfpItem.x, mfpItem.y, mfpItem.z), fs, lvl, [Structure].StructuralType.NonStructural)
                                'Try to get/set material
                                For Each matItemId As ElementId In famInstance.GetMaterialIds(False)
                                    Debug.WriteLine(doc.GetElement(matItemId).Name)
                                Next matItemId
'famInstance.LookupParameter("Martela Material 1").Set(newMat.Id)
'Dim paramMat As Parameter = famInstance.LookupParameter("Martela Material 1")
'doc.FamilyManager.AssociateElementParameterToFamilyParameter(paramMat, famParam1) End If End If familySymbolIds.Clear() familySymbolIds = Nothing If Not fs Is Nothing Then fs.Dispose() : fs = Nothing If Not fam Is Nothing Then fam.Dispose() : fam = Nothing 'If Not famInstance Is Nothing Then famInstance.Dispose() : famInstance = Nothing Next mfpItem

 


Viewing all articles
Browse latest Browse all 66683

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>