Hello
I need to Create a Function called ChangeLayer
public void ChangeLayer (Entity ent, string layerName) { // Here can i change layer }
for any entity (Line, PLine, BlockReference, circle, .... )
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Solved by _gile. Go to Solution.
🙂 sorry i missed
i meant how can i read the layer of block when i insert it from other drawing,
i mean i need to insert the block from other dwg with the same it's layer.
and can i use clone directly form other drawing to current ?? something like copy between drawings
Your request is not very clear.
You should post what you've written so far.
If you use the WBlockCloneObjects() with a BlockReference instance, you'll import also all symbolTableRecord instances (Layer, Linetype, etc.) linked to the block reference.
sorry about my english
i have Drawing 'A" has a block which is name "blk" and it;s layer is "my Layer" with color "1"
now iam opening Drawing "B" , i need to insert "blk" in drawing "B" with the same it's layer "my layer"
i hope now you understand me
What's confusing is the world "block" which may mean BlockReference or BlockTableRecord.
As you say: "a block which is name "blk" and it;s layer is "my Layer" " I suppose you're talking about a block reference (a BlockTableRecord, aka block definition, does not 'have' a Layer).
As said upper, if you 'WBlockClone' (i.e. deep cloning) a block reference, you also clone the Layer the block reference is inserted on.
Here's a little example:
private static ObjectId ImportBlockReference(Database targetDb, string fileName, string blockName) { using (var sourceDb = new Database(false, true)) { sourceDb.ReadDwgFile(fileName, FileOpenMode.OpenForReadAndAllShare, false, null); using (var tr = sourceDb.TransactionManager.StartOpenCloseTransaction()) { var ms = (BlockTableRecord)tr.GetObject( SymbolUtilityServices.GetBlockModelSpaceId(sourceDb), OpenMode.ForRead); ObjectId brId = ObjectId.Null; foreach (ObjectId id in ms) { if (id.ObjectClass.DxfName == "INSERT") { var br = (BlockReference)tr.GetObject(id, OpenMode.ForRead); if (br.Name == blockName) brId = id; } } if (!brId.IsNull) { var ids = new ObjectIdCollection(); ids.Add(brId); var targetId = SymbolUtilityServices.GetBlockModelSpaceId(targetDb); var mapping = new IdMapping(); sourceDb.WblockCloneObjects(ids, targetId, mapping, DuplicateRecordCloning.Ignore, false); if (mapping[brId].IsCloned) return mapping[brId].Value; } } return ObjectId.Null; } }
Running:
var id = ImportBlockReference(databaseOfDrawingB, @"A.dwg", "blk");
Will return the ObjectId of the cloned block reference in drawing B if a reference of "blk" have been found in drawing "A" model space.
Can't find what you're looking for? Ask the community or share your knowledge.