- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm currently experiencing a problem with a code I wrote in C#. The idea is to merge a series of entities based on an OD value and then transform them into an alignment. The entities are of different kinds (Line, 3D polyline, etc.). I decided to transform them all into 2D polylines in order to merge them correctly.
However, depending on the nature of the first entity (here a Line), I create a new entity (a 2D polyline) into which I insert the vertices of the line. The problem is that when I create this new entity, the ObjectID of my new polyline to which other polylines will be added is zero, i.e. the associated ID is zero.
In fact, this poses a problem in this part of the code, where the alignment must be created with a non-zero ObjectID (I get an error). Does anyone have a solution for how to associate a new ObjectId or how to create a polyline with a valid objectid?
else
{
Line line = polyline as Line;
Autodesk.AutoCAD.DatabaseServices.Polyline poly2dd = new Autodesk.AutoCAD.DatabaseServices.Polyline();
//poly2dd.ObjectId = new ObjectId(new IntPtr(long.Parse("2000")));
//ObjectId poly2dd = ee;
//ObjectId poly2dd = polyline.ObjectId;
if (line != null)
{
poly2dd.AddVertexAt(0, new Point2d(line.StartPoint.X, line.StartPoint.Y), 0, 0, 0);
poly2dd.AddVertexAt(1, new Point2d(line.EndPoint.X, line.EndPoint.Y), 0, 0, 0);
poly2dd.Elevation = 0;
if (isFirstElement)
{
isFirstElement = false;
continue;
}
else
{
//IniPLine.UpgradeOpen();
IniPLine.JoinEntity(poly2dd);
//poly2dd.ObjectId = line.ObjectId;
//IniPLine.DowngradeOpen();
}
}
}
}
}
}
IniPLine.SetDatabaseDefaults();
}
// Committing is cheaper than aborting
//btr.AppendEntity(IniPLine);
//tr2.AddNewlyCreatedDBObject(IniPLine, true);
// Get id of layer "alignments" or use id of current layer
ObjectId idLayer = db.Clayer;
LayerTable lt = tr2.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
if (lt.Has("alignments")) idLayer = (lt["alignments"]);
// Get id of the 1st Alignment style or Basic
ObjectId idStyle = civdoc.Styles.AlignmentStyles[0];
if (civdoc.Styles.AlignmentStyles.Contains("Basic")) idStyle = civdoc.Styles.AlignmentStyles["Basic"];
// Get id of the 1st AlignmentLabelSetStyle or Basic
ObjectId idLabelSet = civdoc.Styles.LabelSetStyles.AlignmentLabelSetStyles[0];
if (civdoc.Styles.LabelSetStyles.AlignmentLabelSetStyles.Contains("Basic")) idLabelSet = civdoc.Styles.LabelSetStyles.AlignmentLabelSetStyles["Basic"];
// Set options
PolylineOptions plos = new PolylineOptions();
plos.AddCurvesBetweenTangents = true;
plos.EraseExistingEntities = false;
plos.PlineId = IniPLine.ObjectId;
//plos.PlineId = IniPLine.ObjectId; // /!\!!!
// Create unique name
String nAlign = Alignment.GetNextUniqueName(civdoc.Settings.GetSettings<SettingsCmdCreateAlignmentEntities>().DefaultNameFormat.AlignmentNameTemplate.Value);
//plos.PlineId = IniPLine.ObjectId; // /!\!!!
// Create alignment
ObjectId idAlign = Alignment.Create(civdoc, plos, nAlign, ObjectId.Null, idLayer, idStyle, idLabelSet);
Solved! Go to Solution.