Insert dynamic block with hatch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I am stuck with a dynamic block with hatch.
If I insert it manually and I change the length parameter named 'Distance1', I got the proper behaviour. Hatch follow the boundary.
However, if I insert it by code and I change the length parameter, hatch doesn't follow boundaries.
Here is the result:
I have attached the block.
I did follow the hint (remove the hatch from the stretch action selection) described in
https://forums.autodesk.com/t5/net/update-dynamic-block-hatch/m-p/8681308
but then I have another weird behaviour. Hatch doesn't follow boundary neither the block itself when I change manually the length.
Between the code and the way to create the block, I am lost.
Here is the code to insert block:
'fichier' is the path of the block
'infobloc' is some comment to add
'point' is the position of the block
'onglet' is the name of the layout to insert block (BlockTableRecord.ModelSpace)
'calque' is the name of the layer where to add the block
public static ObjectId InsertionSideDataBase(string fichier, string infobloc, Point2d point, string onglet, Database database, string calque)
{
if (File.Exists(fichier))
{
ObjectId blkid;
ObjectId returnID = ObjectId.Null;
using (Database bdb = new Database(false, true))
{
using (Transaction tr = database.TransactionManager.StartTransaction())
{
bdb.ReadDwgFile(fichier, System.IO.FileShare.Read, true, "");
if (infobloc == null)
blkid = database.Insert(string.Format("{0}", System.IO.Path.GetFileNameWithoutExtension(fichier)), bdb, true);
else
blkid = database.Insert(string.Format("{0} {1}", System.IO.Path.GetFileNameWithoutExtension(fichier), infobloc), bdb, true);
BlockTableRecord acBlkTblRec;
acBlkTblRec = tr.GetObject(blkid, OpenMode.ForRead) as BlockTableRecord;
BlockReference acBlkRef = new BlockReference(TransformPoint2d_3d(point, 0), blkid);
// Open the Block table record for read
BlockTable acBlkTbl;
acBlkTbl = tr.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;
// Open the Block table record Model space for write
BlockTableRecord acBlkTblRec1;
acBlkTblRec1 = tr.GetObject(acBlkTbl[onglet], OpenMode.ForWrite) as BlockTableRecord;
using (acBlkRef)
{
//BlockTableRecord accurspaceblktblrecord = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
returnID = acBlkTblRec1.AppendEntity(acBlkRef);
tr.AddNewlyCreatedDBObject(acBlkRef, true);
acBlkRef.Layer = calque;
if (acBlkTblRec.HasAttributeDefinitions)
{
// Add attributes from the block table record
foreach (ObjectId objID in acBlkTblRec)
{
DBObject dbObj = tr.GetObject(objID, OpenMode.ForRead) as DBObject;
if (dbObj is AttributeDefinition)
{
AttributeDefinition acAtt = dbObj as AttributeDefinition;
if (!acAtt.Constant)
{
using (AttributeReference acAttRef = new AttributeReference())
{
acAttRef.SetAttributeFromBlock(acAtt, acBlkRef.BlockTransform);
acAttRef.Position = acAtt.Position.TransformBy(acBlkRef.BlockTransform);
acBlkRef.AttributeCollection.AppendAttribute(acAttRef);
tr.AddNewlyCreatedDBObject(acAttRef, true);
}
}
}
}
}
}
tr.Commit();
}
}
return returnID;
}
else
{
string message = String.Format("Le fichier {0} n'existe pas", fichier);
throw new ArgumentException(message);
}
}
here is the code to modify the length parametre:
'iD_Dessin' is the ObjectId of the bloc I want to change
'parameter' is the name of the parameter to update (Distance1 in my case)
'valeur' is the new value
public static void EcrireParametreSideDataBase(ObjectId iD_Dessin, string parametre, object valeur)
{
using (Transaction acTrans = iD_Dessin.Database.TransactionManager.StartTransaction())
{
Entity acEnt = acTrans.GetObject(iD_Dessin, OpenMode.ForWrite) as Entity;
if (acEnt != null)
{
BlockReference br = acEnt as BlockReference;
if (br != null)
{
foreach (DynamicBlockReferenceProperty dbrp in br.DynamicBlockReferencePropertyCollection)
{
if (dbrp.PropertyName == parametre)
{
dbrp.Value = valeur;
}
}
}
}
acTrans.Commit();
}
}
Here there something special to manage hatch in dynamic block?
Thanks in advance for your help
Kevin