Script to read block name, copy name and enter as text

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

333onlyhalfevil
Full Member
Posts: 92
Joined: Fri Apr 28, 2023 12:39 pm

Re: Script to read block name, copy name and enter as text

Post by 333onlyhalfevil » Thu Mar 13, 2025 6:36 pm

CVH wrote:
Thu Mar 13, 2025 5:12 pm
And how long thus this 'database' lives?
Variables have block scope.
The lists are created out of the blue or are they hard coded?
Where are they stored within the document for later reference?
Hard coded. And you don't need to store them in the document for later reference because you can just reference the code. This kind of comes back to my last question to you which was unanswered. Is the OP trying to make a tool for him personally for his personal set of block definitions (all of which neither of us, presumably, has never seen?) or is the OP trying to make a tool for everyone? If the answer is for everyone then you should probably ignore the database comment (like you're doing, because it seems like you're defending your own tool, rather than assuming my comments are for the OP and him coding his own tool). If it is for him personally, including a small database seems like it would save a boatload of time over trying to make an automatic program that works for all of his blocks, assuming there are complex blocks that cause problems.
CVH wrote:
Thu Mar 13, 2025 5:12 pm
'Blocks in the sense of Block definitions' ...
... What if I use a Block Reference at a scale, at an angle?
Is that unique Block definitions label position still valid when turned upside down? When mirrored?
Well, you could just have a couple more variables: i.e., blockScale[] and blockAngle[]. Is it still valid when turned upside down or mirrored? I don't know, I'm not the OP and I'm not you. If you're coding this yourself and don't want to do the database option, then don't. If the OP is the one coding this and he isn't the best coder, a simple database that keeps track of some information related to his personal list of blocks might be easier to code for him then some AI tool that can work for any block list from any user.
CVH wrote:
Thu Mar 13, 2025 5:12 pm
As said, automated is kept simple, one Block label (set) for each (selected) Block Reference.
Maybe. Is the OP's list of blocks simple enough for this to be the case? I don't know because I haven't seen his full list of blocks. Have you? You said yourself that "all will fail in some specific situations." It can't be both.
CVH wrote:
Thu Mar 13, 2025 5:12 pm
Simply pointing to the insertion point of the Block Reference but that can be anything.
Yes. It can be anything. We don't know. That's why the OP might want a simple database. To override his main program if he needs to.
CVH wrote:
Thu Mar 13, 2025 5:12 pm
The 3 step interactive mode lets you add the referenced Block name where you want it with the Leader pointing where you set it.
That is: 'Script to read block name, copy name and enter as text' + T2L in one action.
What interactive script mode? Did you program something yourself or are you helping the OP code something? Again, it feels like you're defending the use of your own tool. It feels like you're assuming my comments are critiques on your tool and what your tool needs. I've never seen your tool. I don't know anything about it and can't possibly comment on it or what it needs or doesn't need. My intention with my comments was to provide value to the OP who might not be good enough at coding to do a 3 step interactive mode.

333onlyhalfevil
Full Member
Posts: 92
Joined: Fri Apr 28, 2023 12:39 pm

Re: Script to read block name, copy name and enter as text

Post by 333onlyhalfevil » Thu Mar 13, 2025 7:38 pm

CVH wrote:
Thu Mar 13, 2025 5:12 pm
The 3 step interactive mode lets you add the referenced Block name where you want it with the Leader pointing where you set it.
That is: 'Script to read block name, copy name and enter as text' + T2L in one action.
Oh, one more thing. I made one of these too. Only instead of it automatically inserting the block name it inserts whatever text the user types into a text box on the options bar. The first step is the arrow side of the leader, and the second step is where you want the text to be in relation to the leader head. How does that compare to yours? What's your third step for?

CVH
Premier Member
Posts: 4879
Joined: Wed Sep 27, 2017 4:17 pm

Re: Script to read block name, copy name and enter as text

Post by CVH » Sat Mar 15, 2025 5:56 am

333onlyhalfevil wrote:
Thu Mar 13, 2025 7:38 pm
How does that compare to yours? What's your third step for?
It is not about the third step, the first step is indicating a Block Reference entity.
CVH wrote:
Fri Mar 07, 2025 9:15 am
Would it not be more appropriate to combine all that as a tool that includes a Text entity and a Leader:
- 1) Indicate a Block Reference
- Presented preview is the Text floating in association with a default Leader.
- 2) Indicate Text position
- Presented preview is the Text no longer floating with the arrow tip floating
- 3) Indicate Leader arrow tip position
- Over new until the tool is terminated.
(A WIpeOut under the text would be nice but this entity type is undocumented )
As interactive we can step one level back from state 2 or 3.

Talking about 'OP', reread the post(s) and let us evaluate the original sequence:
- Select a Block Reference entity
- In the Properties Editor, navigate to Specific Properties .. Referenced Block
- Select the entire contents of this text field
- Right-click and choose Copy to the OS Clipboard
- Launch the Text Tool (TE), adjust Font, Font Height, Simple Text and Alignments if necessary
- Overwrite existing text with copied text (Ctrl+V)

A custom tool was requested for the above sequence. (See: 1_expl.jpg)

The text is then inserted in the drawing by the user.
- Hit the OK button of the Text Editor dialog
- With a preview indicate the insertion point for the Text entity.
- Click left to confirm or right to cancel

In a second stage a Leader entity is added based on this Text Entity with 'Leader from selected text' (T2L)
Remind that the Leader will point to the left when the text is aligned different than horizontally 'Right'.
And that the arrow tip has a fixed offset in XY = text height. Both are limitations of the tool.

- Select the text in question.
- T2L (see contributions by dmitpon: 2T or T2L)
- Select the newly created Leader entity
- Drag its arrow point to the desired location and release


I only combined all these steps in an interactive Addon script with a 3 step process as described above.
Not using the OS Clipboard because the referenced Block name is a property of the indicated and queried Block Reference entity.
Not using the Text Editor dialog but querying its last used settings for simple text.
Not limited to left or right as by T2L, the indicated arrow tip position is used to determine left or right.
Above or under is not yet addressed.

It can't be made public with the extra Wipeout entity because we have to wait for the next QCAD release: FS#2651


A hard-coded Block name position offset reference list or 'database' is of no use.
Unless you must have a clear proposal for a Block definition called:
- 'HEA_100_odsejcak_220mm'
- 'PL_G2_1_pogl'
- 'PL_IPE330_umetak_307x75x10_pogl'
- ... and several hundreds more
Then for a related Block Reference entity at any angle or scale what can induce mirroring.

How can I predict which blocks a user has in their drawings?
Or is it the intention that the user adds such offset values in as database and that directly in the script?


The follow up is discouraging.
In a way the 'OP' wants to overcome the lack of XREF capabilities.
Making inserted Library items related to the changes made to these Library items file content.

This could be done by inserting them again one by one at an arbitrary position with 'Overwrite blocks' active.
Deleting those at the arbitrary position afterwards.
But there is no property that tells us if a Block is generated from a Library item.

At least I now have a tool that indicates the referenced Block name and insertion point when indicating near a Block Reference entity.
Typically some third party Block handling is different, the Block content may be nowhere near the Block origin.
The insertion point may thus be miles away from the displayed Block content for a Block Reference entity.
e.g. recent topics: 11506 or 11508

Regards,
CVH

333onlyhalfevil
Full Member
Posts: 92
Joined: Fri Apr 28, 2023 12:39 pm

Re: Script to read block name, copy name and enter as text

Post by 333onlyhalfevil » Mon Mar 17, 2025 7:15 pm

CVH wrote:
Sat Mar 15, 2025 5:56 am
A hard-coded Block name position offset reference list or 'database' is of no use.
Unless you must have a clear proposal for a Block definition called:
- 'HEA_100_odsejcak_220mm'
- 'PL_G2_1_pogl'
- 'PL_IPE330_umetak_307x75x10_pogl'
- ... and several hundreds more
Please don't present one of my points as if it is yours. This quote is the problem with your position, not mine. If you're going to make a factual statement such as "A hard-coded Block name position offset reference list or 'database' is of no use", then you're the one who needs to look through all of the blocks to make sure that statement is correct.

My comment was merely a suggestion to be considered. I said that a future issue for a simple script might be a need to position the text at a specific place for each block since a simple script would place the text at the same place for every block. How would you place the text at specific places for each block without a database? A simple script is going to do the same thing for every single block which may or may not work for Rolinger's set of blocks. Saying that the database is of no use requires you to go through all of the blocks to make sure.

Also, my comment is also for people viewing the thread now and in the future. What if in a year from now, someone wants to place the block name as text in their drawing but they have 5 blocks and these blocks are big and complicated and each has its own requirements as to where the text needs to be placed? The database option is a superior option in a case like that which makes my original comment legitimate. It certainly didn't deserve all this worthless back and forth.
CVH wrote:
Sat Mar 15, 2025 5:56 am
How can I predict which blocks a user has in their drawings?
Again, my comment was intended for Rolinger (and other people viewing the thread now and in the future). How can you predict? You think my comment was intended for you coding Rolinger's script in private via PM? I've also already stated this. Our discussion is going around in circles so I'm not planning on continuing it unless new/good points/information is presented.
CVH wrote:
Sat Mar 15, 2025 5:56 am
Or is it the intention that the user adds such offset values in as database and that directly in the script?
This. But only if his list of blocks needs it because the text positioning resulting from running the simple script is goofy for some of the blocks.
CVH wrote:
Sat Mar 15, 2025 5:56 am
The follow up is discouraging.
In a way the 'OP' wants to overcome the lack of XREF capabilities.
Making inserted Library items related to the changes made to these Library items file content.
I bet the follow up was discouraging. If you're going to code the script for him via PM, I hope you're also billing him for the service. If you don't bill for your time then you're communicating that your time is worthless and the person you're trying to help is going to want more and more and more. This quote sounds like a classic case of takers taking. Making inserted Library items related to the changes made to these Library items file content is quite a bit different than a script to read block name, copy name and enter as text. You should start charging him or make him do it himself.

Also, a lot of forums I've come across over the years have rules against this sort of thing. I've seen a forum with a "We won't do your homework for you rule" where new users are required to demonstrate that they've put effort into solving their question before posting and throughout the discussion. I've also seen a "no private replies" rule where the idea of the thread belongs to the forum/community once the post is made and the ensuing discussion is required to take place within the thread itself. These are good rules IMO. The no doing homework for others rule is a good rule because it makes them learn how to solve their problem themselves and also makes the other members of the community not have to waste so much of their time. It also prevents the recipient of free services from asking for more and more and more. The no private replies rule is also a good one because all of the people viewing the thread now and in the future can't see the private replies. As the thread stands right now, someone coming here looking for an answer to the thread subject wouldn't find an answer because the answer reply was made in private.

CVH wrote:
Sat Mar 15, 2025 5:56 am
Typically some third party Block handling is different, the Block content may be nowhere near the Block origin.
The insertion point may thus be miles away from the displayed Block content for a Block Reference entity.
Ho ho ho. You might want to reconsider my original comment. :roll:

Rolinger
Junior Member
Posts: 18
Joined: Thu Aug 29, 2024 5:17 pm

Re: Script to read block name, copy name and enter as text

Post by Rolinger » Sat Mar 22, 2025 10:34 pm

As the OP, I need to say a few words.
My request was exactly a request for help! I’m not a programmer, but I still tried to create something functional using ChatGPT, DeepSeek, and Gemini. At least 30 iterations, for sure. :roll: Essentially, in this case I’m trying to replicate free LISP programs that exist for AutoCAD— lisp programs that have proven useful and are used by many people.
This quote sounds like a classic case of takers taking.
No, I’m not a "taker," and I’ve never asked anyone to do my homework. What I’m asking for here is something I could easily achieve in other software, but I want to do it in QCAD. In fact, there’s no way here—or on any other forum—to force someone to do work for another person, right? 😊

Yes, CVH helped me in this case https://vimeo.com/manage/videos/1068479526/8ead0c0366, and I’d like to publicly thank him. Why he decided to help in this way, I don’t know! I believe his code is good enough to share with the community. I don’t know CVH personally, nor do we have any private or professional communication, but I can only praise him as someone who sacrifices a lot of his time and knowledge for this community! I’ve also learned a great things just by reading his (of course and others) answers on this forum.

Best Regards, Rolinger

P.S.
What do you think would have happened if Nikola Tesla had behaved like, say, Edison—patenting and commercializing all his inventions? We probably wouldn’t be communicating like this today. It's not all about money. :-)

333onlyhalfevil
Full Member
Posts: 92
Joined: Fri Apr 28, 2023 12:39 pm

Re: Script to read block name, copy name and enter as text

Post by 333onlyhalfevil » Fri Mar 28, 2025 10:44 am

Rolinger wrote:
Sat Mar 22, 2025 10:34 pm
My request was exactly a request for help! I’m not a programmer, but I still tried to create something functional using ChatGPT, DeepSeek, and Gemini.
I think you'd be hard pressed to find a teacher anywhere in the world who would consider LLM output as a legitimate homework submission, but I digress since the QCAD forum doesn't have a rule against not doing your homework before posting. Lucky you. It should. For the record, doing your homework in this context would mean that you know Javascript already; have read through all of the QCAD API programming tutorials; got at least a bare minimum development environment set up so you could edit the code and see the edit's effect in QCAD; searched through the forum to find threads similar in scope to what you're looking for; and at least tried to solve it yourself.
Rolinger wrote:
Sat Mar 22, 2025 10:34 pm
No, I’m not a "taker," and I’ve never asked anyone to do my homework.
So you didn't slowly push CVH's script away from the thread subject in the direction of xref functionality? You also did all of what I said above before posting? Also, your thread is currently unsolved. Anyone viewing your thread now and in the future won't get any practical information as to a "Script to read block name, copy name and enter as text". If you are indeed "not a "taker"", you might want to make a detailed post to help anyone who views this thread. Needing this to be explained is a bad sign though... :roll:
Rolinger wrote:
Sat Mar 22, 2025 10:34 pm
Why he decided to help in this way, I don’t know!
I don't know either! I know he means well and it is coming from a good place but he hurt everyone involved responding this way. He hurt himself by communicating his time isn't worth anything. Hell, I have a laundry list of scripts I'm working on. If it is free, I can keep him busy. He hurt me because if it is free then that means my time spent learning the QCAD API was a waste of time. Not to mention having to waste my time on worthless back and forth about how my comment applies to a knowledgeable coder coding something in private. He hurt the community because, as of this post, anyone who reads through this thread will be wasting their time and not even get an answer by the time they reach the end and also because it is free for you and not for them and his time could've been spent working on QCAD itself. And, last but not least, he hurt you because a "Script to read block name, copy name and enter as text" is the perfect first script for someone to try to write. That opportunity is now lost for you. :(
Rolinger wrote:
Sat Mar 22, 2025 10:34 pm
I don’t know CVH personally, nor do we have any private or professional communication
If you've sent PMs to him through the course of him writing this script for you, then you have both private and professional communication with him. You're striking me as the kind of person who says one thing while doing something different. :roll:
Rolinger wrote:
Sat Mar 22, 2025 10:34 pm

What do you think would have happened if Nikola Tesla had behaved like, say, Edison—patenting and commercializing all his inventions? We probably wouldn’t be communicating like this today. It's not all about money. :-)
This seems like a goofy comparison to try to make while you're coding things in private and when the script CVH wrote for you is still being kept private. :roll: I'm assuming this is in response to my suggestion that CVH bill you for his time? You don't charge for your time working on other people's projects? If it's not all about money then that means you're doing CAD work for free for people, right?

CVH
Premier Member
Posts: 4879
Joined: Wed Sep 27, 2017 4:17 pm

Re: Script to read block name, copy name and enter as text

Post by CVH » Wed May 07, 2025 7:32 am

The Why? is easy and twofold.
I saw potential in the tool request and Rolinger indicated that he was not very familiar with QCAD scripting.

The only way to know what Block a Block Reference is showing is to select it and verify it in the Property Editor.
Scrolling down may be required.
A simple preview of the Block name label when pointing near it is far more easier.
Creating it permanently is not really required but labeling Block References is always an option.

The question Why off-forum? is also easy to answer.
As shown in the video contributed by Rolinger (Thank you) it is a bare minimum.
A quick draft to show how the request could be coded as an all inclusive interactive tool .

For one, Rolinger asked to use the Text Dialog attributes and that may not be the first choice for any user.
The current state is that it includes a preference page to configure those things:
Default font + style, by Text Dialog attributes or by Dimension preferences falling back on defaults when not specified.
Among several other preferences aside from the tool options.

From the start I intended to include a Wipeout entity so that the label text was always readable wherever it was displayed.
This is a novel thing in QCAD and not well documented to start with, see Reference.
My last post there (7/3/2025) indicates that other fixes were still required.

I need to wait at least for the upcoming release of QCAD before publishing it.
See QCAD Changelog after v3.32.2. In detail: FS#2649 (11/03/2025), FS#2650, FS#2651 and FS#2654.

Meanwhile included a curve instead of a hard corner for the Leader.
Included Selection Groups IDs to select and manipulate a label as a whole.
Automatic labeling all/all selected and that may include a database for offsets and positions if you add that yourself.
...

But one thing can never be solved because all entities are unrelated to other content: Labels on top of other labels.
And that will be the biggest hurdle for setting up a personal custom database.


@333onlyhalfevil,
I regard your partly accusatory comments as misplaced frustrations because the tool has not yet been shared publicly.

"Figure it out for yourself" is not a productive answer in any case.

I don't consider myself as a thief or any other user as a 'taker'.
Ifso, then never reply on anything because you are spending your previous time on someone others behalf.

Asking for answers based on little to no input and sharing nothing at all with the community is very selfish.
The community is there to solve things together.
If I solve yours or others, don't blame me for that.

As soon there is a follow up for v3.32.2. it will be published.
No one but Andrew can force that process.

Regards,
CVH

333onlyhalfevil
Full Member
Posts: 92
Joined: Fri Apr 28, 2023 12:39 pm

Re: Script to read block name, copy name and enter as text

Post by 333onlyhalfevil » Thu May 15, 2025 8:26 am

CVH wrote:
Wed May 07, 2025 7:32 am
@333onlyhalfevil,
I regard your partly accusatory comments as misplaced frustrations because the tool has not yet been shared publicly.
I'm not frustrated about this as it's a tool that's similar to one I already have.

What I'm frustrated about is that you're not getting the points that I'm making. :roll: What's frustrating is having to go back and forth with you 10 times defending a comment that was meant for newbies coding a script based on the thread title themselves. Until you release it, other people have to code it themselves. You are not the only person on this forum. The comment I made about the database was meant for newbies, not you. How is that so hard to understand? ::pissed off emoji they don't have:: Do you really not understand the separation between public and private? You're still replying about the public database comment as it relates to your private script. Like, come on. Really? :roll:

And there's only so much time in the day and I don't like seeing someone who has been helping me having someone take free coding services from them for free. The fundamental difference between posting help on a forum and coding scripts in private is that the posts on the forum benefit the community as a whole and coding scripts in private benefits Rolinger only. Private coding services is a skill that people go to work and charge money for. You can code things for people for free if you want, I don't care that much. But you might want to notice when someone is sticking up for you.
CVH wrote:
Wed May 07, 2025 7:32 am
"Figure it out for yourself" is not a productive answer in any case.
I never said this. I said for someone to show that they've at least tried to figure it out themselves first. Big difference.
CVH wrote:
Wed May 07, 2025 7:32 am
I don't consider myself as a thief or any other user as a 'taker'.
If so, then never reply on anything because you are spending your previous time on someone others behalf.
No one said you were a thief. You don't want to view another user as a taker because you're the one getting taken from. Again, there's a difference between public and private. Please make that distinction. Public replies help everyone. Private replies help 1 person. Notice the difference. I'm talking down about the private help for free and you're trying to blanket my reply over everything that's both public and private. If YoU dOnT cOdE tHiNgS fOr PeOpLe FoR fReE iN pRiVaTe ThEn YoU mIgHt As WeLl NoT rEpLy To AnYtHiNg At AlL. :roll: When you reply in public on a forum you're contributing to the community. When you code something for someone in private, you are working for them as a free coding consultant. There's a big difference.
CVH wrote:
Wed May 07, 2025 7:32 am
Asking for answers based on little to no input and sharing nothing at all with the community is very selfish.
The community is there to solve things together.
If I solve yours or others, don't blame me for that.
Is this meant at me or Rolinger or in general? I've posted good information as follow ups to most of my threads. I've also tried to post help multiple times on multiple different threads and you've argued with me about my replies more than once. Don't dominate the forum and argue with people about their posts and then call people selfish for "sharing nothing at all with the community". There's only so much that can be said on these threads. You posting a big giant thing as a reply doesn't make everyone else selfish for not saying anything.

CVH
Premier Member
Posts: 4879
Joined: Wed Sep 27, 2017 4:17 pm

Re: Script to read block name, copy name and enter as text

Post by CVH » Thu May 15, 2025 11:50 am

Your original reply started out on a positive note, but that changed drastically along the way ...

It remains my choice NOT to make something public that is not yet fully supported.
For that I filed several Bug Reports and all have the status fixed.
'Fixed' by Andrew does not mean that your copy of QCAD is up to date.

In the meantime, I'm simply waiting for the RWipeoutEntity resources to be fixed in a newer version of QCAD.

- = - = - = - = -

I never hesitated to share: comments, thoughts, insights, solutions or whatever unless too custom or proprietary.
It would be as simple as asking for a preliminary issue ... Off-forum of course.
Two part-time script developers may be more successful when working together.

Regards,
CVH

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”