BartD Posted December 17, 2024 Posted December 17, 2024 Dear, I receive AutoCAD drawings with Point Blocks that contains attribute data. The attribute data contains good data (don't need to change this), but the tags are wrong and have to be modified. Does anyone know how this can be done? Can the tag be modified in a simple manner or even deleted? Thx Quote
BIGAL Posted December 17, 2024 Posted December 17, 2024 Welcome aboard. You can change a "Tagstring" name in a block. You need though to do it to the block definition then use attsync to update all blocks by that name. What do you know about lisp ? If it is only a few blocks the simplest way is to BEDIT the block, with properties open, when you click on a attribute it shows the tagname and you can change it. There is to much unknown here, need more information about the block. Need a sample dwg and what tagnames are to be changed. Before you do anything else Google "Change tagstring in block autolisp" for me I would do a global routine that works with any block hence search first. Quote
BartD Posted December 18, 2024 Author Posted December 18, 2024 Currently I found another way, with the help of a python script that changes the label names in a DXF. It was AI that wrote me the script and I added the python plugin to Notepad++. Quote
SLW210 Posted December 18, 2024 Posted December 18, 2024 Would you care to share your solution? Quote
BartD Posted December 18, 2024 Author Posted December 18, 2024 (edited) Certainly! Here's a step-by-step guide to create a PythonScript macro in Notepad++ that reads a table of replacements from a CSV file and performs the replacements in the current document. Step 1: Install PythonScript Plugin Open Notepad++. Go to Plugins > Plugins Admin. Search for PythonScript and install it. Step 2: Create the PythonScript Go to Plugins > PythonScript > Show Console. In the console, click on the New Script button. Name your script, for example, ReplaceFromCSV.py. Step 3: Write the Script Copy and paste the following script into the editor: import csv import os from Npp import notepad, editor # Path to your CSV file csv_file_path = 'C:/path/to/your/replacements.csv' # Read the replacements from the CSV file replacements = {} with open(csv_file_path, mode='r') as file: reader = csv.reader(file) for row in reader: if len(row) == 2: replacements[row[0]] = row[1] # Get the current document text text = editor.getText() # Perform the replacements for old_word, new_word in replacements.items(): text = text.replace(old_word, new_word) # Set the modified text back to the editor editor.setText(text) notepad.messageBox("Replacements completed!", "Info") Step 4: Save and Run the Script Save the script. Open the document in Notepad++ where you want to perform the replacements. Go to Plugins > PythonScript > Scripts and select your script (ReplaceFromCSV.py). Step 5: Prepare Your CSV File Create a CSV file with two columns: the first column for the words to find and the second column for the words to replace them with. For example: old_word1,new_word1 old_word2,new_word2 Make sure to update the csv_file_path in the script to the correct path of your CSV file. This script will read the replacements from the CSV file and apply them to the current document in Notepad++. Edited December 18, 2024 by SLW210 Added Code Tags! 1 Quote
BIGAL Posted December 18, 2024 Posted December 18, 2024 (edited) I am confused you are maybe mixing terms about Autocad objects, a Block can have attributes, within the attribute is 2 properties plus others; Tagname Attribute value So I read your 1st post as wanting to change the Tagname, is this correct ? Or are you just trying to change the text value then why not use FIND. I am now understanding your rewriting a dxf file, its not necessary, you can continue maybe with Python acting on a current Autocad dwg, you can get a "Lisp plugin" that does the same you have a current lisp code in Notepad++ and it runs on current dwg. Its sounds to me that you need Blockname,tagname,newstring. Edited December 18, 2024 by BIGAL Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.