Skip to content

Instantly share code, notes, and snippets.

View Civil3DToolChest's full-sized avatar

Civil3DToolChest

View GitHub Profile
@Civil3DToolChest
Civil3DToolChest / addGeneralNoteStyle
Created March 18, 2014 20:45
test command add general note style
[CommandMethod("addGeneralLabelStyle")]
public void addGeneralLabelStyle() // This method can have any name
{
ObjectId labelStyleId = getGeneralLabelStyle("Asphalt");
if (labelStyleId == ObjectId.Null)
{
labelStyleId = addGeneralLabelStyel("Asphalt");
}
setGeneralProperties(labelStyleId, "SHR", "C-ROAD-LABL", true, Autodesk.Civil.OrientationReferenceType.View, true, 110, true);
setTextComponentContents(labelStyleId, "ASPHALT", "Asphalt");
@Civil3DToolChest
Civil3DToolChest / setTextComponentContents
Created March 17, 2014 19:57
set text component contents
public void setTextComponentContents(ObjectId labelStyleId, string contentString, string componentName)
{
Document acadDoc = Application.DocumentManager.MdiActiveDocument;
CivilDocument civilDoc = CivilApplication.ActiveDocument;
using (Transaction trans = acadDoc.Database.TransactionManager.StartOpenCloseTransaction())
{
LabelStyle lblStyle = trans.GetObject(labelStyleId, OpenMode.ForWrite) as LabelStyle;
LabelStyleTextComponent textComponent = trans.GetObject(lblStyle.GetComponents(LabelStyleComponentType.Text)[0], OpenMode.ForWrite) as LabelStyleTextComponent;
textComponent.Name = componentName;
textComponent.Text.Contents.Value = contentString;
@Civil3DToolChest
Civil3DToolChest / setTextComponentContents
Created March 17, 2014 19:07
set general label style contents
public void setTextComponentContents(ObjectIdCollection componentIds, string contentString, string componentName)
{
Document acadDoc = Application.DocumentManager.MdiActiveDocument;
CivilDocument civilDoc = CivilApplication.ActiveDocument;
using (Transaction trans = acadDoc.Database.TransactionManager.StartOpenCloseTransaction())
{
foreach (ObjectId id in componentIds)
{
LabelStyleTextComponent textComponent = trans.GetObject(id, OpenMode.ForWrite) as LabelStyleTextComponent;
textComponent.Name = componentName;
@Civil3DToolChest
Civil3DToolChest / getLabelStyleComponentIds
Created March 17, 2014 18:49
get label style components object id collection
public ObjectIdCollection getLabelStyleComponentIds(ObjectId labelStyleId, LabelStyleComponentType componentType)
{
ObjectIdCollection componentIds = new ObjectIdCollection();
Document acadDoc = Application.DocumentManager.MdiActiveDocument;
CivilDocument civilDoc = CivilApplication.ActiveDocument;
using (Transaction trans = acadDoc.Database.TransactionManager.StartOpenCloseTransaction())
{
LabelStyle lblstyle = trans.GetObject(labelStyleId, OpenMode.ForRead) as LabelStyle;
componentIds = lblstyle.GetComponents(componentType);
trans.Commit();
@Civil3DToolChest
Civil3DToolChest / setGenerallabelStyleProperties
Last active August 29, 2015 13:57
setGeneralLabelStyleProperties
public void setGeneralProperties(ObjectId labelStyleId, string textStyle, string layer, bool visiblity,
Autodesk.Civil.OrientationReferenceType orientationReference, bool planReadability, double prBias
)
{
Document acadDoc = Application.DocumentManager.MdiActiveDocument;
CivilDocument civilDoc = CivilApplication.ActiveDocument;
using (Transaction trans = acadDoc.Database.TransactionManager.StartOpenCloseTransaction())
{
LabelStyle lblstyle = trans.GetObject(labelStyleId, OpenMode.ForWrite) as LabelStyle;
lblstyle.Properties.Label.TextStyle.Value = textStyle;
@Civil3DToolChest
Civil3DToolChest / getGeneralStyleLabel
Created March 12, 2014 15:22
get general label style by name
public ObjectId getGeneralLabelStyle(string name)
{
ObjectId lblId = ObjectId.Null;
Document acadDoc = Application.DocumentManager.MdiActiveDocument;
CivilDocument civilDoc = CivilApplication.ActiveDocument;
Boolean hasStyle = civilDoc.Styles.LabelStyles.GeneralNoteLabelStyles.Contains(name);
if (hasStyle)
{
using (Transaction trans = acadDoc.Database.TransactionManager.StartOpenCloseTransaction())
{
@Civil3DToolChest
Civil3DToolChest / addGeneralLabelStyle
Last active August 29, 2015 13:57
Add General Label Style
public ObjectId addGeneralLabelStyel(string name)
{
ObjectId lblId = ObjectId.Null;
Document acadDoc = Application.DocumentManager.MdiActiveDocument;
CivilDocument civilDoc = CivilApplication.ActiveDocument;
using (Transaction trans = acadDoc.Database.TransactionManager.StartOpenCloseTransaction())
{
lblId = civilDoc.Styles.LabelStyles.GeneralNoteLabelStyles.Add(name);
trans.Commit();
}
@Civil3DToolChest
Civil3DToolChest / selectBlocksOnly
Created March 6, 2014 04:43
select blocks only
[CommandMethod("selectBlocksOnly")]
public void selectBlocksOnly()
{
Document acadDoc = Application.DocumentManager.MdiActiveDocument;
Editor editor = acadDoc.Editor;
PromptSelectionOptions promptSelOpt = new PromptSelectionOptions();
promptSelOpt.MessageForAdding = "Select block objects: ";
TypedValue[] tVs = new TypedValue[] { new TypedValue((int)DxfCode.Start, RXClass.GetClass(typeof(BlockReference)).DxfName) };
SelectionFilter filter = new SelectionFilter(tVs);
PromptSelectionResult result = editor.GetSelection(promptSelOpt, filter);
@Civil3DToolChest
Civil3DToolChest / gist:9381959
Last active August 29, 2015 13:57
basic selection set
[CommandMethod("basicSelSet")]
public void basicSelSet()
{
Document acadDoc = Application.DocumentManager.MdiActiveDocument;
Editor editor = acadDoc.Editor;
PromptSelectionOptions promptSelOpt = new PromptSelectionOptions();
promptSelOpt.MessageForAdding = "Select any objects: ";
PromptSelectionResult result = editor.GetSelection(promptSelOpt);
if (result.Status == PromptStatus.OK)
{
@Civil3DToolChest
Civil3DToolChest / getGeneralNoteStyle
Created February 24, 2014 19:51
get General Note Style
public Autodesk.AutoCAD.DatabaseServices.ObjectId getGeneralNoteStyle(string gnName)
{
Autodesk.AutoCAD.ApplicationServices.Document acadDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Autodesk.Civil.ApplicationServices.CivilDocument civilDoc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;
Autodesk.AutoCAD.DatabaseServices.ObjectId generalNoteStyleId = Autodesk.AutoCAD.DatabaseServices.ObjectId.Null;
using (Autodesk.AutoCAD.DatabaseServices.Transaction trans = acadDoc.Database.TransactionManager.StartOpenCloseTransaction())
{
foreach (Autodesk.AutoCAD.DatabaseServices.ObjectId gnsId in civilDoc.Styles.LabelStyles.GeneralNoteLabelStyles)
{
Autodesk.Civil.DatabaseServices.NoteLabel gns = gnsId.GetObject(Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead) as Autodesk.Civil.DatabaseServices.NoteLabel;