error when duplicate family symbol !

error when duplicate family symbol !

hanogkufu
Explorer Explorer
846 Views
4 Replies
Message 1 of 5

error when duplicate family symbol !

hanogkufu
Explorer
Explorer

Please help me! oput of this mistake??

Screenshot 2024-05-18 032506.png

 

using (Transaction pf = new Transaction(doc))
{
pf.Start("Place Instance");

foreach (PolyLine pLine in pLines)
{
XYZ firstP = pLine.GetOutline().MaximumPoint;

XYZ lastP = pLine.GetOutline().MinimumPoint;

XYZ midP = new XYZ((firstP.X+ lastP.X)/2 , (firstP.Y+ lastP.Y)/2, (firstP.Z + lastP.Z)/2);

IList<XYZ> PLineXYZ = pLine.GetCoordinates();

double l1 = Math.Round(UnitUtils.ConvertFromInternalUnits(PLineXYZ[0].DistanceTo(PLineXYZ[1]), UnitTypeId.Millimeters),0);

double l2 = Math.Round(UnitUtils.ConvertFromInternalUnits(PLineXYZ[1].DistanceTo(PLineXYZ[2]), UnitTypeId.Millimeters), 0);

double Length = l1 > l2 ? l1 : l2;

double Width = l1 < l2 ? l1 : l2;

string symName = Length.ToString() + "x" + Width.ToString() + "x500mm";

FamilySymbol sym = (syms.Where(s => s.Name == symName).FirstOrDefault()) ?? syms[0].Duplicate(symName) as FamilySymbol;

if (!sym.IsActive) sym.Activate();

FamilyInstance instance = doc.Create.NewFamilyInstance(midP, sym, level, StructuralType.Footing);
}
pf.Commit();
}
return Result.Succeeded; 

0 Likes
Accepted solutions (1)
847 Views
4 Replies
Replies (4)
Message 2 of 5

Mohamed_Arshad
Advisor
Advisor

Hi @hanogkufu 

    You are trying to duplicate with existing family symbol name. so the error is popping up. The name which you’re using for duplicate must be unique and no family symbol should use that name

 

Hope this will helps 🙂


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 3 of 5

hanogkufu
Explorer
Explorer

Thank for your answer! But i do the condition above, if the "name" existing it must be assign to  the sym before and didn't create new family symbol

0 Likes
Message 4 of 5

Moustafa_K
Advisor
Advisor
Accepted solution

I think you missed filling back the syms collection with the new created symbol

you need to amend your code to something like this

 

FamilySymbol sym = (syms.Where(s => s.Name == symName).FirstOrDefault());
if (sym == null)
{
    sym = syms[0].Duplicate(symName) as FamilySymbol;
    syms.Add(sym);
}

 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
Message 5 of 5

hanogkufu
Explorer
Explorer

@Moustafa_K  yes it is ! thank you so much!

0 Likes