🙏Enter data to entities with data object - AutoCAD Map 3D.

arperezinf
Advocate

🙏Enter data to entities with data object - AutoCAD Map 3D.

arperezinf
Advocate
Advocate

Hello everyone.

 

I hope they are doing well.

 

I need to create a Lisp command for AutoCAD MAP 3D and when selecting an entity identify which layer it is on.

 

If the feature is in a layer beginning with “POST_”, prompt or allow to enter the street name, after the street name is entered, prompt to enter the height of the street, then prompt to enter the height in meters , then request to enter the material and finally request to enter the state in which it is located.

 

If the feature is in a layer beginning with “PROPERTY_”, prompt or allow to enter the street name, once the street name is entered, prompt to enter the height of the street, then prompt to enter the number of floors, then request to enter the number of apartments, and finally request to enter the number of stores.

 

Then that data is collected, I need it to be saved in the Data Object of the selected element.

 

I was analyzing how to do the command, but I have no idea how to do it. I got a little help from bing chat and chatgpt, but I'm sure that what they did is not right because you have to know how to program lisp and I don't know.

 

I only see that the data can be entered, but I have no idea how to save the data in the OD:POST and OD:PROPERTY.

 

I leave here the code that was generated.

 

 

(defun c:test (/ ss ent layername streetname height floors apartments stores material state)
  (setq ss (ssget))
  (if ss
    (progn
      (setq ent (ssname ss 0))
      (setq layername (cdr (assoc 8 (entget ent))))
      (princ (strcat "\nLa entidad seleccionada se encuentra en la capa: " layername))
      (cond
        ((= "POSTE_" (substr layername 1 6))
          (setq streetname (getstring "\nIngrese el nombre de la calle: "))
          (setq height (getreal "\nIngrese la altura de la calle en metros: "))
          (setq material (getstring "\nIngrese el material: "))
          (setq state (getstring "\nIngrese el estado: "))
          ; Aquí puedes hacer algo con streetname, height, material y state.
        )
        ((= "PROPIEDAD_" (substr layername 1 10))
          (setq streetname (getstring "\nIngrese el nombre de la calle: "))
          (setq height (getreal "\nIngrese la altura de la calle en metros: "))
          (setq floors (getint "\nIngrese el número de pisos: "))
          (setq apartments (getint "\nIngrese el número de departamentos: "))
          (setq stores (getint "\nIngrese el número de locales: "))
          ; Aquí puedes hacer algo con streetname, height, floors, apartments y stores.
        )
        (t
          (princ "\nLa capa no tiene un formato reconocido.")
        )
      )
    )
    (princ "\nNo se ha seleccionado ninguna entidad.")
  )
  (princ)
)

 

 

I hope you can help me.
Thank you so much.

0 Likes
Reply
684 Views
7 Replies
Replies (7)

arperezinf
Advocate
Advocate

Hello @CADaSchtroumpf 

Sorry if I bother you with this again.

 

I did this code but it doesn't work for me, it doesn't load the data collected in the fields.

Could you explain to me why I cannot manage to store the data that I enter in the fields of the blocks, where is the problem, what am I doing wrong?

 

At least I managed to identify the table it belongs to when selecting the block and then with the (COND) command I made a conditional, to show the data I want to request and load.

 

Thank you so much.
Greetings.

 

(defun c:foo ()
  (setq ent (car (entsel "\nElegir objeto con datos OD: ")))
  (setq odname (car (ade_odgettables ent)))

  (cond
    ((equal odname "POSTES")
     ; captura los datos.
     (setq streetname (getstring "\nIngrese el nombre de la calle: "))
     (setq height (getstring "\nIngrese la altura de la calle [SN]: "))
     (setq material (getstring "\nIngrese el material [MADERA/HORMIGON/METAL/HIERRO]: "))
     (setq height_mts (getreal "\nIngrese la altura metros [5/6/7/8/9/12]: "))
     (setq state (getstring "\nIngrese el estado [BUENO/MALO]: "))
     ; ingresar datos.
     (setq streetname (ade_odsetfield odname "NOMBRE_CALLE" 0))
     (setq height (ade_odsetfield ent odname "ALTURA" 0))
     (setq material (ade_odsetfield ent odname "MATERIAL" 0))
     (setq height_mts (ade_odsetfield ent odname "ALTURA_MTS" 0))
     (setq state (ade_odsetfield ent odname "ESTADO" 0))
     ; imprimir datos.
     (princ)
    ;  (princ (strcat "\nNOMBRE_CALLE: " streetname))
    ;  (princ (strcat "\nALTURA: " height))
    ;  (princ (strcat "\nMATERIAL: " material))
    ;  (princ (strcat "\nALTURA_MTS: " height_mts))
    ;  (princ (strcat "\nESTADO: " state))
     (princ)
     )
    
    ((equal odname "PROPIEDAD")
     ; captura los datos.
     (setq streetname (getstring "\nIngrese el nombre de la calle: "))
     (setq height (getstring "\nIngrese la altura de la calle [SN]: "))
     (setq floors (getreal "\nIngrese el numero de pisos [0]: "))
     (setq apartments (getreal "\nIngrese el numero de departamentos [0]: "))
     (setq stores (getint "\nIngrese el numero de locales [0]: "))
     
     ; ingresar datos.
     (ade_odsetfield ent odname "NOMBRE_CALLE" 0 streetname)
     (ade_odsetfield ent odname "ALTURA" 0 height)
     (ade_odsetfield ent odname "CANT_PISOS" 0 floors)
     (ade_odsetfield ent odname "CANT_DEPARTAMENTOS" 0 apartments)
     (ade_odsetfield ent odname "CANT_LOCALES" stores)
     ; imprimir datos.
     (princ)
    ;  (princ (strcat "\nNOMBRE_CALLE: " streetname))
    ;  (princ (strcat "\nALTURA: " height))
    ;  (princ (strcat "\nCANT_PISOS: " floors))
    ;  (princ (strcat "\nCANT_DEPARTAMENTOS: " apartments))
    ;  (princ (strcat "\nCANT_LOCALES: " stores))
     (princ)
    )
    ((equal odname nil)
     (princ "\nNo se encontraron tablas de datos.")
    )
  )
)

 

0 Likes

CADaSchtroumpf
Advisor
Advisor

@arperezinf 

This? briefly tested...

(defun c:foo ( / flag ss ent tbl odname streetname height material height_mts state floors apartments stores)
  (setq flag T)
  (while flag
    (princ "\nElegir objeto con datos OD: ")
    (while (not (setq ss (ssget "_+.:E:S" '((0 . "INSERT"))))))
    (setq
      ent (ssname ss 0)
      tbl (ade_odgettables ent)
    )
    (cond
      ((and tbl (setq odname (car (ade_odgettables ent))))
        (cond
          ((equal odname "POSTES")
            (sssetfirst nil ss)
            (setq streetname (strcase (getstring "\nIngrese el nombre de la calle: ")))
            (setq height (getstring "\nIngrese la altura de la calle <SN>: "))
            (if (eq height "") (setq height "SN"))
            (initget 1 "MADERA HORMIGON METAL HIERRO")
            (setq material (getkword "\nIngrese el material [MADERA/HORMIGON/METAL/HIERRO]: "))
            (initget 1 "5 6 7 8 9 12")
            (setq height_mts (getkword "\nIngrese la altura metros [5/6/7/8/9/12]: "))
            (initget 1 "BUENO MALO")
            (setq state (getkword "\nIngrese el estado [BUENO/MALO]: "))
            (ade_odsetfield ent odname "NOMBRE_CALLE" 0 streetname)
            (ade_odsetfield ent odname "ALTURA" 0 height)
            (ade_odsetfield ent odname "MATERIAL" 0 material)
            (ade_odsetfield ent odname "ALTURA_MTS" 0 (atoi height_mts))
            (ade_odsetfield ent odname "ESTADO" 0 state)
            (sssetfirst nil ss)
          )
          ((equal odname "PROPIEDAD")
            (sssetfirst nil ss)
            (setq streetname (strcase (getstring "\nIngrese el nombre de la calle: ")))
            (setq height (getstring "\nIngrese la altura de la calle <SN>: "))
            (if (eq height "") (setq height "SN"))
            (initget 4)
            (setq floors (getint "\nIngrese el numero de pisos <0>: "))
            (if (not floors) (setq floors 0))
            (initget 4)
            (setq apartments (getint "\nIngrese el numero de departamentos <0>: "))
            (if (not apartments) (setq apartments 0))
            (initget 4)
            (setq stores (getint "\nIngrese el numero de locales <0>: "))
            (if (not stores) (setq stores 0))
            (ade_odsetfield ent odname "NOMBRE_CALLE" 0 streetname)
            (ade_odsetfield ent odname "ALTURA" 0 height)
            (ade_odsetfield ent odname "CANT_PISOS" 0 floors)
            (ade_odsetfield ent odname "CANT_DEPARTAMENTOS" 0 apartments)
            (ade_odsetfield ent odname "CANT_LOCALES" 0 stores)
            (sssetfirst nil ss)
          )
          (T
            (princ "\nNo hay campo correspondiente para esta entidad")
          )
        )
      )
      (T
        (princ "\nNo se encontraron tablas de datos.")
      )
    )
    (initget "Si No")
    (if (eq (getkword "\nContinuar [Si/No]? <Si>: ") "No") (setq flag nil))
    (sssetfirst nil nil)
  )
  (prin1)
)

CADaSchtroumpf
Advisor
Advisor

@arperezinf 

After reading your multi-post on the same subject, I think I just understood your request (at least I believe).
By the way, there is a forum concerning Map3D, I think that you would have more listening on this forum and that you could discover there more tools concerning this vertical product.
Your draft code misled me, here is the one that should answer your request...

(vl-load-com)
(defun c:foo ( / flag ss ent AcDoc Space obj nam_blk nam_lay factor scale_x scale_y scale_z curr_lay NewObj tbl streetname height material height_mts state floors apartments stores)
  (setq flag T)
  (while flag
    (princ "\nElegir objeto con datos OD: ")
    (while (not (setq ss (ssget "_+.:E:S" '((0 . "INSERT") (8 . "POSTE_*,PROPIEDAD_*"))))))
    (setq
      ent (ssname ss 0)
      AcDoc (vla-get-ActiveDocument (vlax-get-acad-object))
      Space
      (if (= 1 (getvar "CVPORT"))
        (vla-get-PaperSpace AcDoc)
        (vla-get-ModelSpace AcDoc)
      )
      obj (vlax-ename->vla-object ent)
      nam_blk (vla-get-EffectiveName obj)
      nam_lay (vla-get-Layer obj)
      factor (vla-get-InsUnitsFactor obj)
      scale_x (* (vla-get-XEffectiveScaleFactor obj) factor)
      scale_y (* (vla-get-YEffectiveScaleFactor obj) factor)
      scale_z (* (vla-get-ZEffectiveScaleFactor obj) factor)
      curr_lay (getvar "CLAYER")
    )
    (setvar "CLAYER" nam_lay)
    (setq
      NewObj
      (vla-InsertBlock
        Space
        (vlax-3d-point (trans (setq pt (getpoint (strcat "\nPunto de inserción para bloque " nam_blk " : "))) 1 0))
        nam_blk
        scale_x
        scale_y
        scale_z
        0
      )
    )
    (vla-put-Rotation NewObj (getangle pt "\nRotación del bloque: "))
    (setq
      ent (entlast)
      ss (ssadd)
    )
    (ssadd ent ss)
    (cond
      ((wcmatch nam_lay "POSTE_*")
        (if (ade_odgettables ent)
          (setq tbl (car (ade_odgettables ent)))
          (progn (setq tbl "POSTES") (ade_odaddrecord ent tbl))
        )
        (setq streetname (strcase (getstring "\nIngrese el nombre de la calle: ")))
        (setq height (getstring "\nIngrese la altura de la calle <SN>: "))
        (if (eq height "") (setq height "SN"))
        (initget 1 "MADERA HORMIGON METAL HIERRO")
        (setq material (getkword "\nIngrese el material [MADERA/HORMIGON/METAL/HIERRO]: "))
        (initget 1 "5 6 7 8 9 12")
        (setq height_mts (getkword "\nIngrese la altura metros [5/6/7/8/9/12]: "))
        (initget 1 "BUENO MALO")
        (setq state (getkword "\nIngrese el estado [BUENO/MALO]: "))
        (mapcar
          '(lambda (x y) (ade_odsetfield ent tbl x 0 y))
          '("NOMBRE_CALLE" "ALTURA" "MATERIAL" "ALTURA_MTS" "ESTADO")
          (list streetname height material (atoi height_mts) state)
        )
        (sssetfirst nil ss)
      )
      ((wcmatch nam_lay "PROPIEDAD_*")
        (if (ade_odgettables ent)
          (setq tbl (car (ade_odgettables ent)))
          (progn (setq tbl "PROPIEDAD") (ade_odaddrecord ent tbl))
        )
        (setq streetname (strcase (getstring "\nIngrese el nombre de la calle: ")))
        (setq height (getstring "\nIngrese la altura de la calle <SN>: "))
        (if (eq height "") (setq height "SN"))
        (initget 4)
        (setq floors (getint "\nIngrese el numero de pisos <0>: "))
        (if (not floors) (setq floors 0))
        (initget 4)
        (setq apartments (getint "\nIngrese el numero de departamentos <0>: "))
        (if (not apartments) (setq apartments 0))
        (initget 4)
        (setq stores (getint "\nIngrese el numero de locales <0>: "))
        (if (not stores) (setq stores 0))
        (mapcar
          '(lambda (x y) (ade_odsetfield ent tbl x 0 y))
          '("NOMBRE_CALLE" "ALTURA" "CANT_PISOS" "CANT_DEPARTAMENTOS" "CANT_LOCALES")
          (list streetname height floors apartments stores)
        )
        (sssetfirst nil ss)
      )
      (T
        (princ "\nLa capa de inserción correspondiente para esta entidad no es válida.")
      )
    )
    (setvar "CLAYER" curr_lay)
    (initget "Si No")
    (if (eq (getkword "\nContinuar [Si/No]? <Si>: ") "No") (setq flag nil))
    (sssetfirst nil nil)
  )
  (prin1)
)

arperezinf
Advocate
Advocate

Hello @CADaSchtroumpf 👋


Sorry for the delay in responding, also for using the AutoCAD forum and not AutoCAD Map 3D, and for the various publications on the same subject, but I am needing a command that allows entering, modifying, deleting, searching and displaying the objects of data in the blocks in AutoCAD Map 3D.

 

I tried both commands, as always their work is very excellent and they are used to do many things.

 

I know you're going to hate me because I made some changes to the command, but it can't put the white window with the command information you posted in this post.

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/insert-blocks-with-data-object-in-au... 

 

(vl-load-com)
(defun c:foo ( / flag ss ent AcDoc Space obj nam_blk nam_lay factor scale_x scale_y scale_z curr_lay NewObj tbl streetname height material height_mts state floors apartments stores)
  (setq flag T)
  (while flag
    (princ "\nElegir objeto con datos OD: ")
    (while (not (setq ss (ssget "_+.:E:S" '((0 . "INSERT") (8 . "POSTE_*,PROPIEDAD_*"))))))
    (setq
      ent (ssname ss 0)
      AcDoc (vla-get-ActiveDocument (vlax-get-acad-object))
      Space
      (if (= 1 (getvar "CVPORT"))
        (vla-get-PaperSpace AcDoc)
        (vla-get-ModelSpace AcDoc)
      )
      obj (vlax-ename->vla-object ent)
      nam_blk (vla-get-EffectiveName obj)
      nam_lay (vla-get-Layer obj)
      factor (vla-get-InsUnitsFactor obj)
      scale_x (* (vla-get-XEffectiveScaleFactor obj) factor)
      scale_y (* (vla-get-YEffectiveScaleFactor obj) factor)
      scale_z (* (vla-get-ZEffectiveScaleFactor obj) factor)
      curr_lay (getvar "CLAYER")
    )
    (setvar "CLAYER" nam_lay)
    (setq
      NewObj
      (vla-InsertBlock
        Space
        (vlax-3d-point (trans (setq pt (getpoint (strcat "\nPunto de inserción para bloque " nam_blk " : "))) 1 0))
        nam_blk
        scale_x
        scale_y
        scale_z
        0
      )
    )
    ;(vla-put-Rotation NewObj (getangle pt "\nRotación del bloque <0>: "))
    (vla-put-Rotation NewObj 0.0)
    (setq
      ent (entlast)
      ss (ssadd)
    )
    (ssadd ent ss)
    (cond
      ((wcmatch nam_lay "POSTE_*")
        (if (ade_odgettables ent)
          (setq tbl (car (ade_odgettables ent)))
          (progn (setq tbl "POSTES") (ade_odaddrecord ent tbl))
        )
        (setq streetname (strcase (getstring "\nIngrese el nombre de la calle: ")))
        (setq height (strcase (getstring "\nIngrese la altura de la calle <SN>: ")))
        (if (eq height "") (setq height "SN"))
        (if (eq height "SN")
          (progn
            (setq height_start (itoa (getint "\nIngrese altura inicial: ")))
            (setq height_end (itoa (getint "\nIngrese altura final: ")))
            (setq streetname (strcat streetname " " height_start "-" height_end))
          )
        )
        (initget 1 "MADERA HORMIGON METAL HIERRO")
        (setq material (getkword "\nIngrese el material [MADERA/HORMIGON/METAL/HIERRO]: "))
        (initget 1 "5 6 7 8 9 12")
        (setq height_mts (getint "\nIngrese la altura metros [5/6/7/8/9/12]: "))
        (initget 1 "BUENO MALO")
        (setq state (getkword "\nIngrese el estado [BUENO/MALO]: "))
        (mapcar
          '(lambda (x y) (ade_odsetfield ent tbl x 0 y))
          '("NOMBRE_CALLE" "ALTURA" "MATERIAL" "ALTURA_MTS" "ESTADO")
          ;(list streetname height material (atoi height_mts) state)
          (list streetname height material height_mts state)
        )
        (sssetfirst nil ss)
      )
      ((wcmatch nam_lay "PROPIEDAD_*")
        (if (ade_odgettables ent)
          (setq tbl (car (ade_odgettables ent)))
          (progn (setq tbl "PROPIEDAD") (ade_odaddrecord ent tbl))
        )
        (setq streetname (strcase (getstring "\nIngrese el nombre de la calle: ")))
        (setq height (strcase (getstring "\nIngrese la altura de la calle <SN>: ")))
        (if (eq height "") (setq height "SN"))
        (if (eq height "SN")
          (progn
            (setq height_start (itoa (getint "\nIngrese altura inicial: ")))
            (setq height_end (itoa (getint "\nIngrese altura final: ")))
            (setq streetname (strcat streetname " " height_start "-" height_end))
          )
        )
        (initget 4)
        (setq floors (getint "\nIngrese el numero de pisos <0>: "))
        (if (not floors) (setq floors 0))
        (initget 4)
        (setq apartments (getint "\nIngrese el numero de departamentos <0>: "))
        (if (not apartments) (setq apartments 0))
        (initget 4)
        (setq stores (getint "\nIngrese el numero de locales <0>: "))
        (if (not stores) (setq stores 0))
        (mapcar
          '(lambda (x y) (ade_odsetfield ent tbl x 0 y))
          '("NOMBRE_CALLE" "ALTURA" "CANT_PISOS" "CANT_DEPARTAMENTOS" "CANT_LOCALES")
          (list streetname height floors apartments stores)
        )
        (sssetfirst nil ss)
      )
      (T
        (princ "\nLa capa de inserción correspondiente para esta entidad no es válida.")
      )
    )
    (alert "Se actualizaron los bloques seleccionados")
    (setvar "CLAYER" curr_lay)
    (initget "Si No")
    (if (eq (getkword "\nContinuar [Si/No]? <Si>: ") "No") (setq flag nil))
    (sssetfirst nil nil)
  )
  (prin1)
)

 

You could make this the white window with the information in the command.

 

I also have another problem that is related to the same thing about the ODs, I am going to consult it in the Map 3D forum.

 

Thank you so much.
Greetings.

0 Likes

CADaSchtroumpf
Advisor
Advisor

A quick assembly of the two functions.
I wouldn't go any further because the request is very personalized; it only benefits you!
Unless paid?!
bye...

arperezinf
Advocate
Advocate

Hello @CADaSchtroumpf 

I hope you're well.
I just saw the command. Excellent work! Very thankful!


Please don't be mad at me. I understand the situation very well, of course the command is only for the problems I have, if it were a problem that many people have, don't you think they would be requesting the same thing? Well, since you touched on the subject of money, could you tell me privately how much you charge and your data to send or deposit money.

 

Thank you so much.
Greetings.

0 Likes

Sea-Haven
Mentor
Mentor

Here is a freebie for you a start for the front end of inputting variables rather than 1 after the other, CADaSchtroumpf welcome to use.

 

(if (not ah:buttscol)(load "Multi Radio buttons 2col.lsp"))
(if (= ah:but nil)(setq ah:but 1))
(if (= ah:but2 nil)(setq ah:but2 1))
(setq lst1 (list "Select" "MADERA" "HORMIGON" "METAL" "HIERRO"))
(setq lst2 (list "Select stories" "5" "6""7" "8" "9" "10" "11" "12"))

(ah:buttscol ah:but ah:but2 "Please choose" lst1 lst2)
(setq ans1 (nth ah:2col lst1))
(setq ans2 (nth ah:2col2 lst2))

 

 

SeaHaven_0-1693008602797.png

 

 

0 Likes