.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

mutliple attributes

0 REPLIES 0
Reply
Message 1 of 1
Dakuan
158 Views, 0 Replies

mutliple attributes

ive been following the c# labs, and have tried to modify the code so that my block has 2 attributes.

defining the AttributeReference outside the loop results in only 1 attribute making it into the inserted block.

defining the attref inside the loop as below, results in an error when run in CAD, but compiles fine...

can anyone point me in the right direction

many thanks,
dom


using System;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

[assembly: CommandClass(typeof(ClassLibrary.HPDVClass))]

namespace ClassLibrary
{
///
/// Summary description for HPDVClass.
///

public class HPDVClass
{
public HPDVClass()
{
//
// TODO: Add constructor logic here
//
}

// Define Command "CREATE"
[CommandMethod("CREATE")]
static public void CreateEmployee()
{
//declare some stuff
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

//start transaction
Transaction trans = db.TransactionManager.StartTransaction();

try
{
//access block table for write
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForWrite);

//create the reference
BlockReference bRef = new BlockReference(new Point3d(0, 0, 0), CreateEmployeeDefinition());

//access modelspace
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);

//create new attribute ref
//AttributeReference attRef = new AttributeReference();

BlockTableRecord empBtr = (BlockTableRecord)trans.GetObject(bt["EmpBlock"],OpenMode.ForRead);
foreach (ObjectId id in empBtr)
{
Entity ent = (Entity)trans.GetObject(id, OpenMode.ForRead);
//AttributeReference attRef = new AttributeReference();


if (ent is AttributeDefinition)
{

AttributeReference attRef = new AttributeReference();
AttributeDefinition attDef = ((AttributeDefinition)(ent));//wtf is this!?

//match the properties
attRef.SetPropertiesFrom(attDef);
attRef.Position = new Point3d(attDef.Position.X + bRef.Position.X, attDef.Position.Y + bRef.Position.Y,
attDef.Position.Z + bRef.Position.Z);
attRef.Height = attDef.Height;
attRef.Rotation = attDef.Rotation;
attRef.Tag = attDef.Tag;
attRef.TextString = attDef.TextString;

bRef.AttributeCollection.AppendAttribute(attRef);
trans.AddNewlyCreatedDBObject(attRef, true);
btr.AppendEntity(bRef);

attRef.Dispose();

}
}


//btr.AppendEntity(bRef);
//bRef.AttributeCollection.AppendAttribute(attRef);
trans.AddNewlyCreatedDBObject(bRef, true);
//trans.AddNewlyCreatedDBObject(attRef, true);
trans.Commit();

}
catch
{
//error message
ed.WriteMessage ("FAIL in CreateEmployee");
}
finally
{
//dispose of objects
trans.Dispose();
db.Dispose();

}
}
0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost