Skip to content

Commit

Permalink
chore(civil3d): changes property sets and parts data to be a Base (#…
Browse files Browse the repository at this point in the history
…3584)

* updates partsdata and property sets to send as base

* do not send property sets if count is 0
  • Loading branch information
clairekuang authored Jul 22, 2024
1 parent 96a6f29 commit 8c32ad4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ ref int convertedCount

#if CIVIL
// add property sets if this is Civil3D
var propertySets = obj.GetPropertySets(tr);
if (propertySets.Count > 0)
if (obj.TryGetPropertySets(tr, out Base propertySets))
{
converted["propertySets"] = propertySets;
}
Expand Down
25 changes: 14 additions & 11 deletions ConnectorAutocadCivil/ConnectorAutocadCivil/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,34 +460,36 @@ public static void SetPropertySets(this Entity entity, Document doc, List<Dictio
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static List<Dictionary<string, object>> GetPropertySets(this DBObject obj, Transaction tr)
public static bool TryGetPropertySets(this DBObject obj, Transaction tr, out Base propertySets)
{
var sets = new List<Dictionary<string, object>>();
ObjectIdCollection propertySets = null;
propertySets = new();

ObjectIdCollection propertySetIds = null;
try
{
propertySets = PropertyDataServices.GetPropertySets(obj);
propertySetIds = PropertyDataServices.GetPropertySets(obj);
}
catch (Autodesk.AutoCAD.Runtime.Exception e)
{
// This may throw if property sets do not exist on the object.
// afaik, trycatch is necessary because there is no way to preemptively check if the set already exists.
return false;
}

if (propertySets is null)
if (propertySetIds is null || propertySetIds.Count == 0)
{
return sets;
return false;
}

foreach (ObjectId id in propertySets)
foreach (ObjectId id in propertySetIds)
{
var setDictionary = new Dictionary<string, object>();
Dictionary<string, object> setDictionary = new() ;

PropertySet propertySet = (PropertySet)tr.GetObject(id, OpenMode.ForRead);
PropertySetDefinition setDef = (PropertySetDefinition)tr.GetObject(propertySet.PropertySetDefinition, OpenMode.ForRead);

PropertyDefinitionCollection propDef = setDef.Definitions;
var propDefs = new Dictionary<int, PropertyDefinition>();
Dictionary<int, PropertyDefinition> propDefs = new();
foreach (PropertyDefinition def in propDef)
{
propDefs.Add(def.Id, def);
Expand All @@ -507,10 +509,11 @@ public static List<Dictionary<string, object>> GetPropertySets(this DBObject obj

if (setDictionary.Count > 0)
{
sets.Add(CleanDictionary(setDictionary));
propertySets[propertySet.Name] = CleanDictionary(setDictionary);
}
}
return sets;

return true;
}

// Handles object types from property set dictionaries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ private Featureline FeaturelineToSpeckle(CivilDB.CorridorFeatureLine featureline
var point = featureline.FeatureLinePoints[i];
baseCurvePoints.Add(point.XYZ);
if (!point.IsBreak) { polylinePoints.Add(point.XYZ); }
if (polylinePoints.Count > 0 && (i == featureline.FeatureLinePoints.Count - 1 || point.IsBreak ))
if (polylinePoints.Count > 1 && (i == featureline.FeatureLinePoints.Count - 1 || point.IsBreak ))
{
var polyline = PolylineToSpeckle(new Polyline3d(Poly3dType.SimplePoly, polylinePoints, false));
polylines.Add(polyline);
Expand Down Expand Up @@ -1029,17 +1029,18 @@ public Structure StructureToSpeckle(CivilDB.Structure structure)
/// <summary>
/// Converts PartData into a list of DataField
/// </summary>
private List<CivilDataField> PartDataRecordToSpeckle(PartDataRecord partData)
private Base PartDataRecordToSpeckle(PartDataRecord partData)
{
Base partDataBase = new();
List<CivilDataField> fields = new();

foreach (PartDataField partField in partData.GetAllDataFields())
{
CivilDataField field = new(partField.Name, partField.DataType.ToString(), partField.Value, partField.Units.ToString(),partField.Context.ToString(), null);
fields.Add(field);
partDataBase[partField.Name] = field;
}

return fields;
return partDataBase;
}

#if CIVIL2022_OR_GREATER
Expand Down

0 comments on commit 8c32ad4

Please sign in to comment.