Polylines lenght

Polylines lenght

sergiu_ciuhnenco
Advocate Advocate
1,683 Views
13 Replies
Message 1 of 14

Polylines lenght

sergiu_ciuhnenco
Advocate
Advocate

Asking for a help from lisp Gurus :
Here is a file with blocks with attributes wich define the position, the quantity and lenght of the rebar ( polyline ); in this file is also the result for what I am asking for !!( a table wich represent each segment lenght of polyline { multiplied by 10} [in excell MROUND function ])
I am do it manually first step I am using this lisp :

Code:
(vl-load-com)
(defun  c:mult-info_po2CSV ( / js file_name cle f_open key_sep str_sep oldim  lst_lay-seg lst_id-seg lst_pt lst_length lst_alpha lst_rad nb id
                              n obj ename pr dist_start dist_end pt_start pt_end seg_len seg_bulge rad alpha)
  (princ "\nSelectionner les polylignes optimisees.")
  (while (null (setq js (ssget '((0 . "LWPOLYLINE")))))
    (princ "\nSelection vide, ou ce ne sont pas des LWPOLYLINE!")
  )
  (command "_.ddunits"
    (while (not (zerop (getvar "cmdactive")))
      (command pause)
    )
  )
   (setq file_name (getfiled "Nom du fichier a creer ?: " (strcat (substr  (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 3)) "csv") "csv"  37))
  (if (null file_name) (exit))
  (if (findfile file_name)
    (progn
      (prompt "\nFichier existe deja!")
      (initget "Ajoute Remplace annUler _Add Replace Undo")
      (setq cle
        (getkword "\nDonnees dans fichier? [Ajouter/Remplacer/annUler] <R>: ")
      )
      (cond
        ((eq cle "Add")
          (setq cle "a")
        )
        ((or (eq cle "Replace") (eq cle ()))
          (setq cle "w")
        )
        (T (exit))
      )
      (setq f_open (open file_name cle))
    )
    (setq f_open (open file_name "w"))
  )
  (initget "Espace Virgule Point-virgule Tabulation _SPace Comma SEmicolon Tabulation")
  (setq key_sep (getkword "\nSeparateur [Espace/Virgule/Point-virgule/Tabulation]? <Point-virgule>: "))
  (cond
    ((eq key_sep "SPpace") (setq str_sep " "))
    ((eq key_sep "Comma") (setq str_sep ","))
    ((eq key_sep "Tabulation") (setq str_sep "\t"))
    (T (setq str_sep ";"))
  )
  (setq oldim (getvar "dimzin"))
  (setvar "dimzin" 0)
  (setq
    lst_lay-seg '()
    lst_id-seg '()
    lst_pt '()
    lst_length '()
    lst_alpha '()
    lst_rad '()
    nb 0
    id 0
  )
  (repeat (setq n (sslength js))
    (setq
      obj (ssname js (setq n (1- n)))
      ename (vlax-ename->vla-object obj)
      pr -1
      id (1+ id)
      nb 1
    )
    (repeat (fix (vlax-curve-getEndParam ename))
      (setq
        dist_start (vlax-curve-GetDistAtParam ename (setq pr (1+ pr)))
        dist_end (vlax-curve-GetDistAtParam ename (1+ pr))
        pt_start (vlax-curve-GetPointAtParam ename pr)
        pt_end (vlax-curve-GetPointAtParam ename (1+ pr))
        seg_len (- dist_end dist_start)
        seg_bulge (vla-GetBulge ename pr)
        rad (if (zerop seg_bulge) 0.0 (/ seg_len (* 4.0 (atan seg_bulge))))
        alpha (if (zerop seg_bulge) (angle pt_start pt_end) 0.0)
        lst_lay-seg (cons (cdr (assoc 8 (entget obj))) lst_lay-seg)
        lst_id-seg (cons (strcat "P" (itoa id) "-" (itoa nb)) lst_id-seg)
        lst_pt (cons pt_start lst_pt)
        lst_length (cons seg_len lst_length)
        lst_rad (cons (abs rad) lst_rad)
        lst_alpha (cons alpha lst_alpha)
        nb (1+ nb)
      )
    )
    (if (eq (vla-get-closed ename) :vlax-false)
      (setq lst_id-seg (cons (strcat "P" (itoa id) "-" (itoa nb)) lst_id-seg))
      (setq lst_id-seg (cons (strcat "P" (itoa id) "-" (itoa (- nb (fix (vlax-curve-getEndParam ename))))) lst_id-seg))
    )
    (setq
      lst_pt (cons pt_end lst_pt) lst_lay-seg (cons (cdr (assoc 8 (entget obj))) lst_lay-seg)
      lst_length (cons 0.0 lst_length) lst_rad (cons 0.0 lst_rad) lst_alpha (cons 0.0 lst_alpha)
      nb (1+ nb)
    )
  )
  ;(write-line (strcat "Sommaire de " (itoa (sslength js)) " LWPOLYLINES") f_open)
  (foreach n
    (reverse
      (mapcar'list
        (append (mapcar '(lambda (x) (strcat x str_sep)) lst_lay-seg) (list (strcat "Calque" str_sep)))
        (append (mapcar '(lambda (x) (strcat x str_sep)) lst_id-seg) (list (strcat "N°" str_sep)))
        (append (mapcar '(lambda (x) (strcat (rtos x) str_sep)) (mapcar 'car lst_pt)) (list (strcat "Coordonnees X" str_sep)))
        (append (mapcar '(lambda (x) (strcat (rtos x) str_sep)) (mapcar 'cadr lst_pt)) (list (strcat "Coordonnees Y" str_sep)))
        (append (mapcar '(lambda (x) (strcat (rtos x) str_sep)) lst_length) (list (strcat "Longueurs" str_sep)))
        (append (mapcar '(lambda (x) (strcat (angtos x) str_sep)) lst_alpha) (list (strcat "Angles" str_sep)))
        (append (mapcar '(lambda (x) (strcat (rtos x) str_sep)) lst_rad) (list (strcat "Rayons" str_sep)))
      )
    )
    (write-line (apply 'strcat n) f_open)
  )
  (close f_open)
  (setvar "dimzin" oldim)
  (prin1)
)

then I have few formulas there , but it takes to much times
If it's not possible : I have another question :
is it possible in lisp that I attached to export also in excell the polyline
ObjId number (example 879607830404
Is it possible to create an attribute in my block witch also may reprezent this ObjId number , then for me it will be more easy to associate them in excell

I know it could be done quick, but only with your help!!!!!!!!
THANKS IN ADVANCE !!!!!!!!!

0 Likes
Accepted solutions (2)
1,684 Views
13 Replies
Replies (13)
Message 2 of 14

braudpat
Mentor
Mentor

 

Hello

 

It is just general Info ...

 

This beautiful routine has been written by Bruno ...I know him !

http://cadxp.com/index.php?/topic/37455-extraction-des-coordonnees-de-polylignes/

Pseudo: bonuscad on the French site: cadxp.com

Pseudo: CADaStroumph on the French/US ADSK Forums

 

Regards, Patrice

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


Message 3 of 14

sergiu_ciuhnenco
Advocate
Advocate

I make an acoount but I can't write at this forum : Vous ne pouvez pas répondre à ce sujet
Could you write him please and direct him to this forum ?
Or copy this post to that forum !!!
Thanks in advance !!

 

0 Likes
Message 4 of 14

braudpat
Mentor
Mentor

 

Hello

 

Bruno knows your demand !

I think that he will maybe answer you ...

 

Regards, Patrice

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 5 of 14

CADaSchtroumpf
Advisor
Advisor
Accepted solution

It is not my part (reinforcing pattern layout), but with your drawing by example, here's what I've done.
The first column is the 'handle' of the entity, it must be in text format in Excel if you want to retrieve the corresponding entity.

 

(defun round_number (xr n / )
  (* (fix (atof (rtos (/ xr n) 2 0))) n)
)
(defun c:for_sergiu ( / js dxf_cod lremov mod_sel str_sep oldim file2open f_open ename pr nb lst_id-seg lst_length lst_rad dist_start dist_end seg_len seg_bulge rad typ)
  (princ "\nSelect model polyline for filtering: ")
  (while
    (null
      (setq js
        (ssget "_+.:E:S"
          (list
            '(0 . "LWPOLYLINE")
            (cons 67 (if (eq (getvar "CVPORT") 1) 1 0))
            (cons 410 (if (eq (getvar "CVPORT") 1) (getvar "CTAB") "Model"))
            '(70 . 0)
            '(-4 . "<OR")
              '(90 . 2) '(90 . 4) '(90 . 6)
            '(-4 . "OR>")
          )
        )
      )
    )
    (princ "\nIsn't an available object!")
  )
  (vl-load-com)
  (setq dxf_cod (entget (ssname js 0)))
  (foreach m (foreach n dxf_cod (if (not (member (car n) '(0 67 410 8 6 62 48 420 70))) (setq lremov (cons (car n) lremov))))
    (setq dxf_cod (vl-remove (assoc m dxf_cod) dxf_cod))
  )
  (setq dxf_cod (append dxf_cod '((70 . 0) (-4 . "<OR") (90 . 2) (90 . 4) (90 . 6) (-4 . "OR>"))))
  (initget "Single All Manual")
  (if (not (eq (setq mod_sel (getkword "\nSelect mode, [Single/All/Manual]<Manual>: ")) "Single"))
    (if (eq mod_sel "All")
        (setq js (ssget "_X" dxf_cod))
        (setq js (ssget dxf_cod))
    )
  )
  (setq
    str_sep ";"  ;-> **** YOU CAN CHANGE THIS STRING BY WHAT YOU WONT ! **** <-
    oldim (getvar "dimzin")
  )
  (setvar "dimzin" 0)
  (cond
    (js
      (setq
        file2open (strcat (getvar "DWGPREFIX") (getvar "DWGNAME") ".CSV")
        f_open (open file2open "w")
      )
      (repeat (setq n (sslength js))
        (setq
          ename (vlax-ename->vla-object (ssname js (setq n (1- n))))
          pr -1
          nb 0
          lst_id-seg '()
          lst_length '()
          lst_rad '()
        )
        (repeat (fix (vlax-curve-getEndParam ename))
          (setq
            dist_start (vlax-curve-GetDistAtParam ename (setq pr (1+ pr)))
            dist_end (vlax-curve-GetDistAtParam ename (1+ pr))
            seg_len (- dist_end dist_start)
            seg_bulge (vla-GetBulge ename pr)
            rad (if (zerop seg_bulge) 0.0 (/ seg_len (* 4.0 (atan seg_bulge))))
            lst_id-seg (cons nb lst_id-seg)
            lst_length (cons seg_len lst_length)
            lst_rad (cons (abs rad) lst_rad)
            nb (1+ nb)
          )
        )
        (setq
          lst_id-seg (cons nb lst_id-seg)
          id_ename (vla-get-handle ename)
          typ (length lst_id-seg)
        )
        (write-line
          (strcat
            "\"" id_ename "\""
            (cond
              ((eq typ 6)
                (strcat
                  ";"
                  "2"
                  ";"
                  (rtos (nth 2 lst_length) 2 0)
                  ";"
                  (rtos (round_number (nth 0 lst_length) 10) 2 0)
                  ";"
                  (rtos (nth 1 lst_rad) 2 0)
                  ";"
                  (rtos (apply '+ lst_length) 2 0)
                )
              )
              ((eq typ 4)
                (strcat
                  ";"
                  "1"
                  ";"
                  (rtos (nth 2 lst_length) 2 0)
                  ";"
                  (rtos (round_number (nth 0 lst_length) 10) 2 0)
                  ";"
                  (rtos (nth 1 lst_rad) 2 0)
                  ";"
                  (rtos (apply '+ lst_length) 2 0)
                )
              )
              ((eq typ 2)
                (strcat
                  ";"
                  "0"
                  ";"
                  (rtos (nth 0 lst_length) 2 0)
                  ";"
                  "0"
                  ";"
                  (rtos (nth 0 lst_rad) 2 0)
                  ";"
                  (rtos (apply '+ lst_length) 2 0)
                )
              )
            )
          )
          f_open
        )
      )
      (close f_open)
      (princ (strcat "\nWritten in the file -> " file2open))
    )
  )
  (setvar "dimzin" oldim)
  (prin1)
)
Message 6 of 14

sergiu_ciuhnenco
Advocate
Advocate

It work realy nice, but it have a small nuance: the last letter or number is not recognizing corectly, but I make a searching match from previous and could be done !!!
Thanks CADaStroumph very much !!!!!

 

0 Likes
Message 7 of 14

sergiu_ciuhnenco
Advocate
Advocate

Hi CADaStroumph , could I ask you to review one more time the code , because some of the recognizing blocks are absolutely mistaken; some ones 3 characters are recognizing !!!
Thanks in advance for your help !!!!

0 Likes
Message 8 of 14

CADaSchtroumpf
Advisor
Advisor

In my code I absolutely do not address the blocks, only lwpolylines that have 2, 4 or 6 vertices and having commnunes properties.
The code analysis simply lwpolylines to provide the information and his handle.
Personally, in this case, I would have turned to xdata instead of blocks to store information (at least there will be no link between polyline and block)
But this challenges your existing work. . .

 

PS:I'm use translator, French -> English

0 Likes
Message 9 of 14

sergiu_ciuhnenco
Advocate
Advocate

First coloumn from your exporting excell (handle code) have aproximatelly the same handle code with blocks that I am exporting with attout comand !!!
And I was thinking , haven't Idea how , but your code is searching handle code from blocks and export it in excell to polyline that define it.
Sorry for my english also !!! tu pouvais ecrire en francais aussi , j'etoudie la langue francais aussi a l'ecole . 🙂

0 Likes
Message 10 of 14

CADaSchtroumpf
Advisor
Advisor

OK Sergiu (Serge?)

 

Attention lors de l'import sous excel car il peut transformer certain handle en réel (ex: 6E1 -> 60)

Pour ma part je préfère Libre Office qui demande si la colonne doit être du texte ou un nombre lors de l'import.

 

Ce "handle" te permet de retrouver les infos par programmation ex: (entget (handent "6E1"))

 

Pour illustrer mes propos sur les XDATA je te joins 2 fichiers lisp que j'avais fais il y a déjà pas mal de temps.

Tu essayes dans un nouveau dessin en commençant par la commande "CABLAGE" (après avoir chargé le lisp)

Tu te crée ou transforme des polylignes existantes.

Puis tu utilise l'autre lisp "TAB_CABLE" pour créer le tableau de calpinage.

 

Ceci pour te monter les possibilités avec les xdata sans recourir à logiciel externe de tableur type  excel.

 

Cela demande un investissement en programmation, et de bien identifier tout ses besoins, donc de réflexion...

Je ne sais pas si tu veux te diriger dans cette voie... c'est ardu mais beaucoup plus puissant que les blocs: les infos sont directement attachées à l'objet, pas de lien à gérer!

0 Likes
Message 11 of 14

sergiu_ciuhnenco
Advocate
Advocate
C'est quelque nouvelle chose pour moi, je éprouvé  jamais!

0 Likes
Message 12 of 14

sergiu_ciuhnenco
Advocate
Advocate

Ici c'est un example complet
https://www.dropbox.com/sh/16oetz0mrv78b9a/AADN_VKs75kvdtzm6L9hPkYza?dl=0

peut tu me dire s'il est possible de faire la spécification en utilisant le lisp que tu aves me donné ? ou c'est déjà soumis pour un autre poste?
Je serai très heureux si tu m'aiderais avec la question dans ce post
Merci d'avance !!!!!

0 Likes
Message 13 of 14

CADaSchtroumpf
Advisor
Advisor
Accepted solution

Bonjour Sergius,

 

Voici comment je procéderais avec ton dessin.

 

- En tout premier lieu utilise la commande "_AUDIT" pour corriger les erreurs que comporte ton dessin.

 

- Utilise la commande "SERGIUS" créer par le lisp. (Autocad can display that don't respond) mais laisse faire la procédure jusqu'au bout (cela peut être un petit peu long). Une fois fait tu peux utiliser la commande "XDLIST" (des ExpressTools) pour voir que des données étendues sont affectées aux polylignes situées sur le calque "ARMATURA..."

 

- Dès lors tu peux utiliser la commande TAB_SERGIUS créer par le 2ème lisp pour produire ton fichier CSV et l'importer avec le tableur de ton choix Excel ou LibreOffice.

 

Je n'ai aucune connaissance en armature béton. J'ai fais cela avec les infos de ton dessin, c'est hors de mon domaine et je ne souhaite pas aller plus loin.

 

Message 14 of 14

sergiu_ciuhnenco
Advocate
Advocate

Comme les americains disent :It's aseome !!!!!!!!!
En francais , ce superrrrrr !!!!! tu avais fait un tres beaux travail !!! Merci beaucoup !!!! Smiley Happy

 

0 Likes