Assign Object Data to Geometrie Data

Assign Object Data to Geometrie Data

fsg09
Explorer Explorer
757 Views
5 Replies
Message 1 of 6

Assign Object Data to Geometrie Data

fsg09
Explorer
Explorer
I have lines in my Drawing. All of them has Start Z and End Z geometry-values. In the Object Data every line has variables named Start_z and Ende_Z. I want to copy all Start_Z-Values to the Start Z Geometry-Value and all Ende_Z-Values to the Ende Z Geometry-Values.

How i can do this automatically?

0 Likes
Accepted solutions (1)
758 Views
5 Replies
Replies (5)
Message 2 of 6

CADaSchtroumpf
Advisor
Advisor
Accepted solution

It would have been easier if you had provided a drawing extract.
I suggest this which will have to be executed in 2 times (for each end of the lines)

;; ListBox (gile)
;; Boite de dialogue permettant un ou plusieurs choix dans une liste
;;
;; Arguments
;; title : le titre de la boite de dialogue (chaîne)
;; msg ; message (chaîne), "" ou nil pour aucun
;; keylab : une liste d'association du type ((key1 . label1) (key2 . label2) ...)
;; flag : 0 = liste déroulante
;; 1 = liste choix unique
;; 2 = liste choix multipes
;;
;; Retour : la clé de l'option (flag = 0 ou 1) ou la liste des clés des options (flag = 2)
;;
;; Exemple d'utilisation
;; (listbox "Présentation" "Choisir une présentation" (mapcar 'cons (layoutlist) (layoutlist)) 1)
(defun ListBox (title msg keylab flag / tmp file dcl_id choice)
  (setq
    tmp (vl-filename-mktemp "tmp.dcl")
    file (open tmp "w")
  )
  (write-line
    (strcat "ListBox:dialog{label=\"" title "\";")
    file
  )
  (if (and msg (/= msg ""))
    (write-line (strcat ":text{label=\"" msg "\";}") file)
  )
  (write-line
    (cond
      ((= 0 flag) "spacer;:popup_list{key=\"lst\";")
      ((= 1 flag) "spacer;:list_box{key=\"lst\";")
      (T "spacer;:list_box{key=\"lst\";multiple_select=true;")
    )
    file
  )
  (write-line "}spacer;ok_button;}" file)
  (close file)
  (setq dcl_id (load_dialog tmp))
  (if (not (new_dialog "ListBox" dcl_id))
    (exit)
  )
  (start_list "lst")
  (mapcar 'add_list (mapcar 'cdr keylab))
  (end_list)
  (action_tile
    "accept"
    "(or (= (get_tile \"lst\") \"\")
      (if (= 2 flag)
        (progn
          (foreach n (str2lst (get_tile \"lst\") \" \")
            (setq choice (cons (nth (atoi n) (mapcar 'car keylab)) choice))
          )
          (setq choice (reverse choice))
        )
        (setq choice (nth (atoi (get_tile \"lst\")) (mapcar 'car keylab)))
      )
    )
    (done_dialog)"
  )
  (start_dialog)
  (unload_dialog dcl_id)
  (vl-file-delete tmp)
  choice
)
(defun C:test ( / AcDoc sel_tbl def_tbl l_field field ss n ent dxf_ent value p)
  (setq AcDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vlax-for l (vla-get-layers AcDoc)
    (if (eq (vlax-get l 'Freeze) -1) (vlax-put l 'Freeze 0))
    (if (eq (vlax-get l 'Lock) -1) (vlax-put l 'Lock 0))
    (if (zerop (vlax-get l 'LayerOn)) (vlax-put l 'LayerOn -1))
  )
  (vla-Regen AcDoc acActiveViewport)
  (while (not (setq sel_tbl (listbox "Object Data" "Select the table of object data" (mapcar 'cons (ade_odtablelist) (ade_odtablelist)) 1))))
  (setq
    def_tbl (ade_odtabledefn sel_tbl)
    l_field (mapcar 'cdr (mapcar '(lambda (x) (assoc "ColName" x)) (cdaddr def_tbl)))
  )
  (while (not (setq field (listbox "Field of data" "Select the data field to transfert at properties" (mapcar 'cons l_field l_field) 1))))
  (setq ss (ssget "_X" '((0 . "LINE"))))
  (cond
    (ss
      (repeat (setq n (sslength ss))
        (setq
          ent (ssname ss (setq n (1- n)))
          dxf_ent (entget ent)
        )
        (cond
          ((member sel_tbl (ade_odgettables ent))
            (setq value (ade_odgetfield ent sel_tbl field 0))
            (cond
              ((eq field "Start_Z")
                (setq p (cdr (assoc 10 dxf_ent)))
                (entmod (subst (cons 10 (list (car p) (cadr p) value)) (assoc 10 dxf_ent) dxf_ent))
              )
              ((eq field "Ende_Z")
                (setq p (cdr (assoc 11 dxf_ent)))
                (entmod (subst (cons 11 (list (car p) (cadr p) value)) (assoc 11 dxf_ent) dxf_ent))
              )
            )
          )
        )
      )
    )
  )
  (prin1)
)
Message 3 of 6

fsg09
Explorer
Explorer

I attached an example as suggested.

Can you specify how to use the script in Map 3D (Im new to this Software) and which lines i need to change with my Attribute-Field-Names. Thanks for your help

0 Likes
Message 4 of 6

ChicagoLooper
Mentor
Mentor

Hi @fsg09 

Do you have Civil3D?

You can easily do this in Civil3D, without lisp. 

In your example (Post #3), all you need are the coordinates (x,y,z's) for five points.

Number each point, in a clockwise direction, from 101 to 105. (Points 101 and 105 will both have the same xyz's.)

 

At your command, Civil will draw a line from 101 to 102, then 102 to 103, 103 to 104, etc., etc. 

Since 101 and 105 have the exact same coordinates, your end point will be the same as the start point.

 

If you have the xyz's in a spreadsheet, you don't even need to insert the points. Civil3D will use your spreadsheet and insert the points for you. 

 

The workflow:

  1. Give your spreadsheet to C3D.
  2. Give command to 'connect' the points (in numerical order of course) and C3D will connect them using a line. 

Click Draw Lines to Connect the Points down below to watch the video.

ChicagoLooper_0-1711559313046.png

 

Chicagolooper

EESignature

0 Likes
Message 5 of 6

O_Eckmann
Mentor
Mentor

Hi @fsg09 ,

 

You can install this plug-in : https://apps.autodesk.com/MAP3D/fr/Detail/Index?id=7146835859656784994&appLang=fr&os=Win64 

And follow this screencast :

 

Olivier Eckmann

EESignature

Message 6 of 6

CADaSchtroumpf
Advisor
Advisor

@fsg09  a écrit :

I attached an example as suggested.

Can you specify how to use the script in Map 3D (Im new to this Software) and which lines i need to change with my Attribute-Field-Names. Thanks for your help



To test, you can select on the forum in the code from line 16 inclusive until the end (line 106),
copy then paste into the Autocad command line, validate the copy by entry and C:TEST appears.
Then type TEST on the command line:
A dialog box is displayed, you choose the table (in your example drawing "cad_z")
Another dialog box is displayed to select a field ("Ende_Z" "Start_Z")
After selecting a field, you will have to repeat the operation to select the other field.
After these two operations, your lines will have their start and end Z's

0 Likes