Having Troubles with Blocks and Text Tags #961
Replies: 4 comments 4 replies
-
Try to save the DXF file as DXF R2013 from AutoCAD. If this doesn't help you have to post your code and the DXF file from AutoCAD as a zip archive. |
Beta Was this translation helpful? Give feedback.
-
Hi there, thanks for your suggestion. I have created the blocks drawing as r2013 dxf, but unfortunately nothing has changed. Please see the attached as requested. I have excluded code where I am trying to 'access' the Tag (this is because I am not 100% sure how to do it, and a lot of things I tried kept giving an error). |
Beta Was this translation helpful? Give feedback.
-
Hi!
The only solution that works is to remove all extension dictionaries from the entities in the block. from pathlib import Path
import ezdxf
from ezdxf import colors
from ezdxf import xref
CWD = Path(r"C:\Users\mozman\Desktop\Now\ezdxf\961")
# Read the file where my blocks live
source_doc = ezdxf.readfile(CWD / "blocksdoc2013.dxf")
# Create a new DXF document.
target_doc = ezdxf.new(dxfversion=source_doc.dxfversion, units=source_doc.units)
# Load blocks by the xref module
block_loader = xref.Loader(source_doc, target_doc)
for block_name in ["FUSEDXF", 'CIRCUIT_BREAKERDXF']:
block = source_doc.blocks.get(block_name)
for entity in block:
entity.discard_extension_dict()
block_loader.load_block_layout(block)
# execute import process
block_loader.execute()
target_doc.layers.add("Layer1", color=colors.YELLOW, lineweight=30)
msp = target_doc.modelspace()
msp.add_blockref('FUSEDXF', (0,0), dxfattribs={"layer": "Layer1"})
target_doc.saveas(CWD / "output.dxf") This works, but also removes some unknown data!!! The best solution is always to use the source document as template: from pathlib import Path
import ezdxf
from ezdxf import colors
CWD = Path(r"C:\Users\mozman\Desktop\Now\ezdxf\961")
# load the source doc as template
doc = ezdxf.readfile(CWD / "blocksdoc2013.dxf")
doc.layers.add("Layer1", color=colors.YELLOW, lineweight=30)
msp = doc.modelspace()
msp.add_blockref('FUSEDXF', (0,0), dxfattribs={"layer": "Layer1"})
# export as new DXF document
doc.saveas(CWD / "output.dxf") Composing new DXF documents from multiple DXF files often fail because newer AutoCAD versions use many undocumented entities and features which can be preserved by |
Beta Was this translation helpful? Give feedback.
-
Deep down the rabbit hole I found the culprit
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi There,
I'd consider myself very much a beginner; so I very much think I am missing something - but I cannot seem to find any answers so far!
My goal is to have a 'blocksdoc' dxf file that contains a number of blocks in a single place. This document is created and saved from within Autocad 2024 to r2018. Each of these blocks has one or more Tags of single line text (no multiline etc.).
I have been able to import these blocks into my ezdxf generated dxf file (test.dxf), and I can place the blocks, however the Tag doesn't seem to exist' and looking at the 'Launcher' tool, there is no 'attdef' section under my block.
However, if I create the block using ezdxf (say for example a file named ezdxfblock), and follow the same process of importing this dxf file into to my test.dxf file, and use the Launcher tool, I can see the 'attdef'.
Note: Even with it there I am still uncertain how to actually populate it.
If someone could guide me on the first issue of not having the attdef present, when the block has been generated in Autocad, and also assist in how to access the Tag, I would be most grateful!
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions