cart: empty [ Login ]

Block attributes being misplaced

1 
Sandeep Bhat
5/10/2022 12:41 PM
Hi Wout, I am trying to add a block along with its attributes from an existing dwg to a new dwg file. When doing this I see the attribute texts being misplaced. However when I click on the sync button on the Block Attribute Manager, they fit well. Is there a way I can call Sync from the CadLib as well? Below is my code. I have also attached all the pictures. Thanks in advance.
C# Code:
private void InsertSourceBlockInTargetModel(DxfModel sourceModel, DxfModel targetModel) { double positionX = 525; double positionY = 375; double positionZ = 0; var cloneContext = new CloneContext(sourceModel, targetModel, ReferenceResolutionType.CloneMissing); foreach (var sourceBlock in sourceModel.Blocks) { var clonedBlock = (DxfBlock)sourceBlock.Clone(cloneContext); targetModel.Blocks.Add(clonedBlock); var sourceDxfInsert = (DxfInsert)FindBlockInsertions(this.sourceModel, sourceBlock); var targetDxfInsert = new DxfInsert(clonedBlock, new Point3D(positionX, positionY, positionZ)); foreach (var attribute in sourceDxfInsert.Attributes) { var clonedAttribute = (DxfAttribute)attribute.Clone(cloneContext); targetDxfInsert.Attributes.Add(clonedAttribute); } targetDxfInsert.ApplyInsertionPointOffsetToAttributes(); targetModel.Entities.Add(targetDxfInsert); } cloneContext.ResolveReferences(); static DxfEntity FindBlockInsertions(DxfModel sourceModel, DxfBlock sourceBlock) => ScanEntityCollectionForBlockInsertions(sourceModel.Entities, sourceBlock); static DxfEntity ScanEntityCollectionForBlockInsertions(IEnumerable<DxfEntity> collection, DxfBlock block) => collection.First(entity => entity is DxfInsert insert && insert.Block == block); }
block_attribute_manager_sync.jpg
Source.jpg
Target_after_sync.jpg
Target_before_sync.jpg
Sandeep Bhat
5/12/2022 7:09 AM
Hi Wout, Any idea why this might be happening? Anything I am missing? Any help is appreciated! Thanks in advance.
Wout
5/12/2022 8:59 AM
You didn't attach your input data. Also make sure your code compiles. - Wout
Sandeep Bhat
5/12/2022 12:58 PM
The code compiles fine. I have attached the source dwg that I am trying to include blocks from. The target model is a new instance of DxfModel, basically an empty model. Do you need the sample project as well?
Wout
5/13/2022 8:16 AM
Hi, Please order a support ticket here, since this is not a bug in CadLib. I can answer quick questions for no cost on the forum, but there have been a couple of non-bug posts by now. - Wout
Sandeep Bhat
5/23/2022 7:29 AM
Hi Wout, I agree this is not a bug in CadLib, rather a feature that I am expecting which mimics the ATTSYNC command behavior in Autocad. Do you have anything that is close to ATTSYNC because clearly the insert.ApplyInsertionPointOffsetToAttributes()does not seem to be working. Best Regards, Sandeep
1