Does a block and a clipped block have different block Id or same?

Does a block and a clipped block have different block Id or same?

prem_kumar8SXZJ
Enthusiast Enthusiast
696 Views
7 Replies
Message 1 of 8

Does a block and a clipped block have different block Id or same?

prem_kumar8SXZJ
Enthusiast
Enthusiast

Hi everyone, I am slightly confused about the difference between a normal block and a clipped block. Does it have a different block ID and if yes how can we find and copy the clipped blocks instead of the normal blocks because the block name is the same for both the blocks?

Any help would be appreciated.

0 Likes
Accepted solutions (1)
697 Views
7 Replies
Replies (7)
Message 2 of 8

_gile
Consultant
Consultant

Hi,

When clipped, a block reference keeps the same ObjectId.

We can know if a block reference is clipped (even inactive clip) by checking its extension dictionary (DBDictionary) which must contain a "ACAD_FILTER" dictionary (DBDictionary) with a "SPATIAL" entry (SpatialFilter).

 

Here's an extension method using other ones defined in this Extension library.

/// <summary>
/// Evaluates if the block reference is clipped.
/// </summary>
/// <param name="br">Instance to which the method applies.</param>
/// <param name="tr">Transaction or OpenCloseTransaction tu use.</param>
/// <returns>true, if the block reference is clipped; false, otherwise.</returns>
public static bool IsClipped(this BlockReference br, Transaction tr) =>
    br.TryGetExtensionDictionary(tr, out DBDictionary extensionDictionary) &&
    extensionDictionary.TryGetNamedDictionary(tr, "ACAD_FILTER", out DBDictionary filterDictionary) &&
    filterDictionary.Contains("SPATIAL");


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 8

prem_kumar8SXZJ
Enthusiast
Enthusiast

Hi @_gile , I am trying to copy the clipped blocks from one drawing to another using block Id but in the new drawing the clipping boundary of the block is not coming instead it is coming as a full block. Ie there any way to copy the block with its clipped boundary so that when I copy the block it will copy same as old drawing. I am using AutoCAD .NET API for C#.

0 Likes
Message 4 of 8

_gile
Consultant
Consultant

Do you use WBlockCloneObjects to copy the block references?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 8

prem_kumar8SXZJ
Enthusiast
Enthusiast

Yes, I am defining a rectangular area by giving 2 points in the code and then I am checking if any block reference is in the specified area if yes I add its block id to ObjectIdCollection and then I use this collection to copy the blocks to a new drawing. Here is the code for your reference.

ObjectIdCollection bIds = new ObjectIdCollection();
[CommandMethod("CopyEntitiesInArea")]
public void CopyEntitiesInArea()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;

Point3d startPoint = new Point3d(720584.413, 2784591.731, 0);
Point3d endPoint = new Point3d(725570.341, 2783949.934, 0);

// Define the selection window
PromptSelectionResult selRes = ed.SelectWindow(startPoint, endPoint);
if (selRes.Status == PromptStatus.OK)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;

foreach (ObjectId objId in selRes.Value.GetObjectIds())
{
Entity ent = tr.GetObject(objId, OpenMode.ForRead) as Entity;
if (ent is BlockReference)
{
BlockReference blockRef = ent as BlockReference;
string blockName = blockRef.Name;
BlockTableRecord modelSpace = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
bIds.Add(blockRef.Id);
}
else
{
ed.WriteMessage("This entity is not a block");
}
}
tr.Commit();
}
}
else
{
ed.WriteMessage("\nNo objects selected.");
}


Document document = Application.DocumentManager.MdiActiveDocument;
Database database = document.Database;
Editor editor = document.Editor;
string localRoot = Application.GetSystemVariable("LOCALROOTPREFIX") as string;
string tempPath = "D:\\CopyBlock.DWG";
DocumentCollection documentCollection = Application.DocumentManager;
Document newDocument = documentCollection.Add(tempPath);
Database newDatabase = newDocument.Database;

using (DocumentLock docLock = newDocument.LockDocument())
{
Application.DocumentManager.MdiActiveDocument = newDocument;
using (Transaction transaction = newDatabase.TransactionManager.StartTransaction())
{
IdMapping mapping = new IdMapping();
database.WblockCloneObjects(bIds, newDatabase.BlockTableId, mapping, DuplicateRecordCloning.Ignore, false);
transaction.Commit();
}
}
documentCollection.MdiActiveDocument = newDocument;
newDocument.Database.SaveAs("Drawing2", DwgVersion.Current);
}

0 Likes
Message 6 of 8

_gile
Consultant
Consultant
Accepted solution

You're adding the clones of the selected block references to the new Database block table which does not make sense:

 

database.WblockCloneObjects(bIds, newDatabase.BlockTableId, mapping, DuplicateRecordCloning.Ignore, false);

 

You should add these clones to the model space BlockTableRecord of the new Database.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 8

prem_kumar8SXZJ
Enthusiast
Enthusiast

Thank you! I have made changes to the code and now its working Thanks for that.
One more things I wanted to ask you. After inserting the blocks I want to scale and rotate the blocks and also I want to change the base point and insertion point of the blocks, In my previous code I am doing it by either blockId or Block name, but now How can I do it?

 

 

For any of you who want the soluting check this code:
newDatabase.WblockCloneObjects(bIds, blockTableRecord.ObjectId, mapping, DuplicateRecordCloning.Replace, false);

0 Likes
Message 8 of 8

gourav_patilG5JXK
Explorer
Explorer

how to clip a block

 

0 Likes