🙏Insert blocks with data object in AutoCAD Map 3D.

arperezinf
Advocate
Advocate

🙏Insert blocks with data object in AutoCAD Map 3D.

arperezinf
Advocate
Advocate

Hello everyone 👋

I hope you are well.

 

Sorry if I bother you with this problem I have.

 

Can any of you help me to create a lisp command, for AutoCAD Map, that allows to select the blocks with data object properties, load the values to those data object properties and insert the block.

 

I attach a file called "Block-Object-Data.dwg", where all the blocks are, I also upload an image called "Object data", so you can see the properties of data objects that the blocks contain.

 

Note: The only way I found, so that the data object properties remain in the blocks, was copying and pasting, but it is very annoying, because the idea is to be able to select the block, load the data object properties and insert the block.

 

I thank you in advance for reading the message, for your comments and help.

Thank you so much.🙏

0 Likes
Reply
Accepted solutions (1)
1,377 Views
16 Replies
Replies (16)

ВeekeeCZ
Consultant
Consultant

How about some sort of Match Object Properties tool?

0 Likes

CADaSchtroumpf
Advisor
Advisor

@arperezinf 

A precision that is important.
Do you want to attach only the object data table and put your own values ​​in the fields?
or
Do you want to attach the object data table AND have the same values ​​attached to the fields as those in your legend?

0 Likes

Sea-Haven
Mentor
Mentor

Object Data, or OD if you google you will find lots of code about get and put Object data.

 

SeaHaven_0-1690501424104.png

 

I have this but it was done for a specific OD properties and can not remember if tested.

 

; https://www.cadtutor.net/forum/topic/73848-lisp-routine-to-replace-block-with-non-block-object/

; By Alanh OCT 2020 info@alanh.com.au
; swap blocks but keep OD data


(DEFUN C:ODBLK ( / blk1 blk2 ss tabname fieldnames x y ent ent2 inspt fval)

(setq blk1 (entsel "\nPick 1st block for name OD data "))

(setq blk2 (entsel "\nPick 2nd block for replacement "))


; DO IF NOT BLOCK

(setq blkn (cdr (assoc 2 (entget (car blk1)))))
(setq blkn2 (cdr (assoc 2 (entget (car blk2)))))

(setq ss (ssget (list (cons 0 "INSERT")(cons 2 blkn))))



(repeat (setq x (sslength ss))
(setq ent (ssname ss (setq x (1- x))))
(setq tabname (ade_odgettables ent))

(setq fieldnames nil count 0)

(foreach Y (cdr (assoc "Columns" (ade_odtabledefn (nth count tabname))))
   (if (not (member (cdr (assoc "ColName" Y)) fieldnames))
    (setq fieldnames (cons (list (nth count tabname)(cdr (assoc "ColName" Y))(ade_odgetfield ent "Tabela" (cdr (assoc "ColName" Y)) 0)     ) fieldnames))
   )
)
  
  
(setq inspt (cdr (assoc 10 (entget ent))))
(entdel ent)
(command "-insert" blkn2 inspt 1 1 0)

(setq ent2 (entlast))
(ade_odaddrecord ent2 (nth 0 (nth 0 fieldnames)))
(foreach fval fieldnames
(ade_odsetfield ENT2  (nth 0 fval) (nth 1 fval) 0 (nth 2 fval))
)

)

(PRINC)
)


 

0 Likes

arperezinf
Advocate
Advocate
Hello everyone!
Sorry for the delay in responding. Thank you very much for your comment.

A Match Object Properties tool sounds like a useful and versatile tool, I would have to try it, see if it can work for me, because what I'm trying to do is insert a block that contains object data properties, which the only way I currently I have so that the values of the data objects that the blocks contain are inserted correctly, it is by copying and pasting the block in the drawing.

If you can, please share the tool and I'll try.

Thank you so much. Greetings.
0 Likes

arperezinf
Advocate
Advocate
Hello CADSchtroumpf.

Hello

Sorry for the delay in answering. Thank you very much for your comment.

I would like to be able to complete the fields of the data object property that the blocks have, in a faster and more agile way.

The steps I am currently using are the following:

1. Select and copy the block containing the data objects.
2. I paste the copied block with the data objects in the place I need.
3. I select the pasted block to see the data object properties.
4. Complete the data object properties of the block.

Those steps, I would like to be able to do them through a lisp command, that allows me to select the block that I want to insert, fill in the data object fields and insert it in the place that I need.

I hope you can understand me.

Thank you so much. Greetings.
0 Likes

CodeDing
Advisor
Advisor

@arperezinf ,

 

Can you post an example drawing with a couple of your blocks and properties please?

 

Best,

~DD


Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
0 Likes

arperezinf
Advocate
Advocate
Hello Sea-Haven!

Sorry about the delay in responding.

Thank you very much for his comment. I have been looking for information on how to solve the problem I have in google, I still can't find the way, but thanks for the information.

Regarding your code, I tried it several times, but I can't get it to work, it keeps asking me to designate objects.

But hey, as I said in previous messages, the idea is to insert any block that is in the cad drawing that you uploaded with its data object properties.

Currently, the way I'm using to insert the blocks with the data object properties is by copying and pasting the block, because if I insert them with the insert blocks command, it inserts the block, but without the object properties.

So if I could select the block, load the OD properties to it and insert it where I need it, this would be a goal!

Thank you so much. Greetings.
0 Likes

arperezinf
Advocate
Advocate

Hello CodeDing!

Thank you very much for your comment.

Yes I can, now I post an example.

Greetings.

0 Likes

arperezinf
Advocate
Advocate

Hello everyone @ВeekeeCZ , @CADaSchtroumpf , @Sea-Haven  and @CodeDing 👏

 

This is a small example of how the blocks would look.

 

If you see the drawing on the side and select one of the blocks that are there, you will be able to see the data object properties and the information that each block has loaded.

 

I hope this can help you understand my problem.

 

Thank you very much for your comments and help.

Greetings.

0 Likes

CADaSchtroumpf
Advisor
Advisor

@arperezinf  a écrit :

Hello everyone @ВeekeeCZ , @CADaSchtroumpf , @Sea-Haven  and @CodeDing 👏

 

This is a small example of how the blocks would look.

 

If you see the drawing on the side and select one of the blocks that are there, you will be able to see the data object properties and the information that each block has loaded.

 

I hope this can help you understand my problem.

 

Thank you very much for your comments and help.

Greetings.


Hello,

This lisp with the command name "Dyn_Insert" will put the cursor in selection mode.
As soon as you move this cursor over an existing block insertion, a label will appear informing you of the name of the block and its layer.
You can still move to another insertion if this insertion is not suitable, the new label will replace the previous one.
If there is therefore an apparent label and you simply validate with a right-click, the insertion command will be launched by taking over the properties (block name, layer, line type, color, thickness and scale of the line type ) of the last selected object.
On the other hand if object data is present for Map3D, it will also be copied. The insertion will be highlighted by the grips and if the property palette is open you can change the object data fields directly in it if they are not to your liking

0 Likes

arperezinf
Advocate
Advocate
Hello @CADaSchtroumpf

Sorry for the delay in answering.
Thank you very much for your comment and help.

Interesting command. I see that he has some things that I could maybe use, let's do something with his command.

You can modify the command, so that it shows in the white window, only the information of the block where it says OD: PROPERTY, I need it to do only that, to show the OD information.

Thank you so much.
0 Likes

CADaSchtroumpf
Advisor
Advisor
Accepted solution

@arperezinf  a écrit :
You can modify the command, so that it shows in the white window, only the information of the block where it says OD: PROPERTY, I need it to do only that, to show the OD information.

@arperezinf 

Maybe this will suit you?
However I noticed in your example drawing that some block was made of another block with its object data included by default. This made me look for a bug in my code when there was none (a lot of time wasted).
It's not a good idea to leave object data in a block definition, you should at least detach it inside the block.
So depending on where the cursor will be on a part of this block, it will not duplicate the correct information: either those defined on the insertion of the block, or that which is in the definition of the block.

arperezinf
Advocate
Advocate

Hello @CADaSchtroumpf 👋

 

I hope you're well.

 

I apologize for the problem with the block that is created from another block. Unfortunately, I can't change the blocks, because they were not created by me.

 

Well, coming to the topic, I was testing the command that you posted and as I said before, the command is interesting.

 

I also saw the error, which you are talking about with the block named "POSTE_MEDIA_TENSION", I understand that the error will only happen with that block and I see that from the same block, two blocks can be obtained, the "POSTE_MEDIA_TENSION" block, which will have information and this other block "POSTE" and it will not have information, but it's okay.

 

Let's continue, I'm going to ask you several questions, to see if you can modify them in the command, if you can't, please tell me.

 

Questions:

 

1. It will be possible, before inserting the copied block with information, to open a window, such as "OD: PROPERTY", to change that information, before inserting the block.

 

2. It will be possible to make the white window, where the information appears, if you press or any other key, disappear or close.

 

3. If I press the "ESC" key, the information window will not disappear, and if I press "ESC" again, it will disappear and the command will be activated again.

 

I hope it continues well, thank you very much for your comments and help.

 

Greetings.

0 Likes

CADaSchtroumpf
Advisor
Advisor

@arperezinf  a écrit :

Let's continue, I'm going to ask you several questions, to see if you can modify them in the command, if you can't, please tell me.

 

Questions:

 

1. It will be possible, before inserting the copied block with information, to open a window, such as "OD: PROPERTY", to change that information, before inserting the block.

 

2. It will be possible to make the white window, where the information appears, if you press or any other key, disappear or close.

 

3. If I press the "ESC" key, the information window will not disappear, and if I press "ESC" again, it will disappear and the command will be activated again.

 

I hope it continues well, thank you very much for your comments and help.

 

Greetings.


@arperezinf 

Hi,

I've inserted some error handling which I hope will work and should resolve undo issues.
The last post containing the lisp has been upgraded as an attachment.

For your first question, although I understood it, for me does not bring more than what I did.
The block have the grips activated at the end of the command and all object data is visible AND editable in the properties palette, which seems simpler to me...
Reminder: to activate/deactivate the properties palette: Ctrl+1 (key 1 of the alpha-numeric part of the keyboard)

0 Likes

arperezinf
Advocate
Advocate

Hello @CADaSchtroumpf 👋

Sorry for the delay in answering.

You are right.

I was testing the command with the change you made, excellent, now the window disappears.
Well I give this problem as solved.
Thank you very much for the help and the command.

Greetings.

0 Likes

arperezinf
Advocate
Advocate

Hello everyone! @ВeekeeCZ @Sea-Haven @CodeDing @CADaSchtroumpf 

 

Sorry if I come back to this topic again.

Can you help me create this one command that will add the data to the blocks.

 

Step 1. Select an element (Block). 
Step 2. Check if the item is a "POLE" or "PROPERTY".

 

If it is a POLE:

Step 2.1 If a POLE is selected
Step 2.2. Enter the NOMBRE_CALLE.
Step 2.3. Enter ALTURA (Default: "SN"). If the ALTURA is different from "SN", continue with Step 3.
If in the ALTURA the predefined value "SN" is chosen, do the substeps.
Step 2.3.1 Enter ALTURA INICIAL.
Step 2.3.2 Enter ALTURA FINAL.
Step 2.3.3 Concatenate "NOMBRE_CALLE ALTURA INICIAL - ALTURA FINAL".
Step 3. Select the MATERIAL (Defaults: "Wood, Concrete, Iron").
Step 4. Select ALTURA_MTS (Default values: "4, 6, 7, 8, 9, 12" and that allows entering another numerical value).
Step 5. Select ESTADO (Presets "Good, Bad").
Step 6. Store the data in the fields of the selected block.
Step 7. Send a message If the data was added or not.
Step 8. Ask if new data needs to be loaded. (Predefined values "Yes, No").
Step 9. If the answer in step 8 is "Yes", go back to step 1.
Step 10. If the answer in step 8 is "No", exit the command.

 

If it is a PROPERTY:

Step 2.1 If a PROPERTY is selected

Step 2.2. Enter the NOMBRE_CALLE.
Step 2.3. Enter ALTURA (Default: "SN"). If the ALTURA is different from "SN", continue with Step 3.
If in the ALTURA the predefined value "SN" is chosen, do the substeps.
Step 2.3.1 Enter ALTURA INICIAL.
Step 2.3.2 Enter ALTURA FINAL.
Step 2.3.3 Concatenate "NOMBRE_CALLE ALTURA INICIAL - ALTURA FINAL".
Step 3. Enter CANT_PISOS (Default value "0").
Step 4. Enter CANT_DEPARTMENTOS (Default value "0").
Step 5. Enter CANT_LOCALES (Default value "0").
Step 6. Store the data in the fields of the selected block.
Step 7. Send a message If the data was added or not.
Step 8. Ask if new data needs to be loaded. (Predefined values "Yes, No").
Step 9. If the answer in step 8 is "Yes", go back to step 1.
Step 10. If the answer in step 8 is "No", exit the command.

 

Note: You can add something like this to the command you did. In case it can be added to the command that was done that step 1 is not done, but go to step 2 and that steps 8, 9 and 10 are not done and start the command again, to insert another block.

 

I hope you can help me with this problem.
Thank you so much.
Greetings.

0 Likes