Jump to content

Please some help with xdata attached to entities


Isaac26a

Recommended Posts

Hi, I'm creating a program that imports points, and goes very well at importing, but i'm trying to keep track of the location of them by attaching the point number to the point with extended data, and I'm still having problems with it.

 

;;;*************************************************************************

;;;  point number
   (entmake 
      (list (cons 0  "TEXT")      
            (cons 40 0.3)        
            (cons 62 256) 
            (cons 1 num)   
            (cons 72 0)   
            (cons 8 "urb_pt_num")   
            (cons 10 posnum)        
            (cons 7 "romans")    
      )
   )
   (setq thenumber (cdr (assoc 5 (entget (entlast)))))
;;; Create the point
   (entmake 
      (list (cons 0  "point")      
            (cons 100 "AcDBpoint") 
            (cons 8 "urb_pt")         ;;; Layer
            (cons 10 loc)
            (cons 62 256)            ;;; Color
      )
   )
   (setq oldlist (entget (entlast)))
   (setq data '((-3 ("urb_pt"
                                              (1000 . (vl-prin1-to-string num))               ;;; Point number, here I already tried (1000 . num);; (1000 . (princ num));; (1000 . (vl-princ-to-string num));; (1000 . (strcat num)), but nothing works
                                             (1000 . descrip)                                                  ;;; Point description
                                             (1005 . thenumber)                                          ;;; Assoc 5 of the text with the point number,  also HERE I'm having problems
                    )
                )
               )
   )

   (setq newlist (append oldlist data))
   (entmod newlist)

   ;;;****************************************************************

 

In the bolded part I'm having problems and keeps giving me errors, I tried just to check (1000 . "test" ) and this one did worked, but I can't make the variable content to be settled

Here is where I'm looking for some wise advice if possible. Please tell me what I Am doing wrong and how to correct it. Thanks in advance for your help.

Link to comment
Share on other sites

You have to build the list in a way that the num, descrip and thenumber are evaluated. Quote sign reads literary what is following, without evaluation. Also, you can entmake directly with the xdata attached.

;;; Create the point
   (entmake 
     (list
       (cons 0  "point")      
       (cons 8 "urb_pt")
       (cons 10 loc)
       (cons 62 256)
       (list -3
         (list
           "urb_pt"
           (cons 1000 num)
           (cons 1000 descrip)
           (cons 1005 thenumber)
         )
       )
     )
   )

 

Link to comment
Share on other sites

11 hours ago, Stefan BMR said:

You have to build the list in a way that the num, descrip and thenumber are evaluated. Quote sign reads literary what is following, without evaluation. Also, you can entmake directly with the xdata attached.


;;; Create the point
   (entmake 
     (list
       (cons 0  "point")      
       (cons 8 "urb_pt")
       (cons 10 loc)
       (cons 62 256)
       (list -3
         (list
           "urb_pt"
           (cons 1000 num)
           (cons 1000 descrip)
           (cons 1005 thenumber)
         )
       )
     )
   )

Hi Stefan, I already tried this solution, and also with (1000 . num) but still keeps giving me the Error:Bad DXF Group: (-3... I don´t know why, do you think it's my AutoCAD, I'm using Civil3D 2010.

 

Link to comment
Share on other sites

8 hours ago, Grrr said:

Here is some useful subfunction from Lee Mac, (LM:data->xdata) that may be of help.

 

I saw this before, but still haven´t tried it, maybe it does help me, I'll try it. thanks

Link to comment
Share on other sites

1 hour ago, BIGAL said:

Any reason why not a block can have attribute "Number" set to invisible much easier.

Well actually I want to keep it being points to possibly allow users to use them for other purposes like to create TINs or some others., thanks, for the option.

Link to comment
Share on other sites

8 hours ago, Isaac26a said:

Hi Stefan, I already tried this solution, and also with (1000 . num) but still keeps giving me the Error:Bad DXF Group: (-3... I don´t know why, do you think it's my AutoCAD, I'm using Civil3D 2010.

You can imagine I've tested my code before posting and it works here.

Post your code with the DXF Group error and the complete error message.

Link to comment
Share on other sites

Played with  Tins for over 40 years, points as a block is not a problem, if needed convert back to a 3d point. Or in civ3D etc can read a csv file direct and make a TIN.

 

If you want TINS what are you using to make them ?  Most Civil software has the options about labelling the points.

 

Have you looked at this http://lee-mac.com/ptmanager.html may be very useful.

Link to comment
Share on other sites

On 11/1/2020 at 9:27 AM, Stefan BMR said:

You can imagine I've tested my code before posting and it works here.

Post your code with the DXF Group error and the complete error message.

Maybe you're totally right and I have some other error before on my code.

The error that I get is:

error: bad DXF group: (-3 ("urb_pt" (1000 . NUM) (1000 . DESCRIP) (1005 . 
THENUMBER) (1005 . THEELEVATION) (1005 . THEDESCRIPTION)))

An the code is the following

 

;;;;;;;;;;;; Program that import points.
;;;;;;;;;;;;
;;;;;;;;;;;; 
;;;;;;;;;;;; 20201029 V1.1 It's created
;;;;;;;;;;;;

(vl-load-com)
(defun c:import2 (/ arch descrip thenumber thedescription theelevation linea loc newlist num oldlist posdes poselev posnum
                     x y z z1)
   (setvar "cmdecho" 0)
   (vl-cmdf "_.undo" "_begin")
;;;   (oldvars)          ;;; To store the current variables
;;;   (newvars)

   (setq arch (getfiled "Selec the file with the points ( Pt,Y,X,Z,Description )" "" "*;*" 4))   
   (setq arch (open arch "r"))
   (if (/= arch nil)
      (progn
         (vl-cmdf "_.layer" "_m" "urb_pt" "_c" "1" "" "" 
                  "_.layer" "_m" "urb_pt_num" "_c" "5" "" ""
                  "_.layer" "_m" "urb_pt_elev" "_c" "5" "" ""
                  "_.layer" "_m" "urb_pt_desc" "_c" "5" "" ""
                  "_.style" "romans" "romans" "0" "1" "" "" "" ""
         )
         (setvar "pdmode" 35)
         (setvar "pdsize" 0.3)
         (regapp "urb_pt")                 ;;; App registry
      )        
   )
   (while (setq linea (read-line arch))
          (setq num (substr linea 1 (vl-string-position (ascii ",") linea)))
          (setq linea (substr linea (1+ (pos "," linea))))
          (setq y (atof linea))
          (setq linea (substr linea (1+ (pos "," linea))))
          (setq x (atof linea))
          (setq linea (substr linea (1+ (pos "," linea))))
          (setq z (atof linea))
          (setq linea (substr linea (1+ (pos "," linea))))
          (setq descrip linea)
          (setq loc (list x y z))
          (createpoint)
   ) ;;; End while
   (close arch)

   (vl-cmdf  "._zoom" "E")

   (reset)
   (vl-cmdf "_.undo" "_end")
   (princ "\n")
   (princ)
)  ;;; End Importa


;;; Function that gives the position of the next element
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun pos (subcad cad / cnt)
   (setq cnt 1)
   (while (and (/= subcad (substr cad cnt (strlen subcad))) (< cnt (strlen cad)))
      (setq cnt (1+ cnt))
   ) ;;; End while
   (if (= subcad (substr cad cnt (strlen subcad)))
      (eval cnt)
      (eval 0)
   ) ;;; End if
) ;;; End pos


;;; Function to create the point
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun createpoint()
  (setq posnum (list (+ x 0.5) (+ y 0.5)))
;;; Point number
   (entmake 
      (list (cons 0  "TEXT")      
            (cons 40 0.3) 
            (cons 62 256) 
            (cons 1 num)  
            (cons 72 0)    
            (cons 8 "urb_pt_num") 
            (cons 10 posnum)      
            (cons 7 "romans")     
      )
   )
   (setq thenumber (cdr (assoc 5 (entget (entlast)))))
   (setq poselev (list (+ x 0.5) y))
   (evalcoma z 3)
   (setq z1 printval)
;;; The elevation of the point
   (entmake 
      (list (cons  0  "TEXT")      
            (cons 40 0.3)     
            (cons 62 256)        
            (cons 1 z1)     
            (cons 72 0)        
            (cons 8 "urb_pt_elev") 
            (cons 10 poselev)      
            (cons 7 "romans")     
      )
   )
   (setq theelevation (cdr (assoc 5 (entget (entlast)))))
   (setq posdes (list (+ x 0.5) (- y 0.5)))
;;; Point description
   (entmake 
      (list (cons 0  "TEXT")      
            (cons 40 0.3)     
            (cons 62 256)        
            (cons 1 descrip)    
            (cons 72 0)        
            (cons 8 "urb_pt_desc") 
            (cons 10 posdes)      
            (cons 7 "romans")     
      )
   )
   (setq thedescription (cdr (assoc 5 (entget (entlast)))))
;;; Creates the point
;;;   (entmake 
;;;      (list
;;;         (cons 0  "point")      
;;;         (cons 8 "urb_pt")
;;;         (cons 10 loc)
;;;         (cons 62 256)
;;;         (list -3
;;;            (list
;;;               "urb_pt"
;;;               (1000 . num)
;;;               (1000 . descrip)
;;;               (1005 . thenumber)
;;;            )
;;;         )
;;;      )
;;;   )
   (entmake 
      (list (cons 0  "point")      
            (cons 100 "AcDBpoint") 
            (cons 8 "urb_pt")         ;;; Layer
            (cons 10 loc)
            (cons 62 256)            ;;; Color
      )
   )
   (setq oldlist (entget (entlast)))
   (setq data '((-3 ("urb_pt"
                       (1000 . num)         ;;; Point number
                       (1000 . descrip)     ;;; Description
                       (1005 . thenumber)     ;;; Assoc 5 of the text that holds the point number
                       (1005 . theelevation)     ;;; Assoc 5 of the text that holds the elevation
                       (1005 . thedescription)     ;;; Assoc 5 of the text that holds the description
                    )
                )
               )
   )
   (setq newlist (append oldlist data))
   (entmod newlist)
   
   (princ)
) ;;; End Createpoint

 

Maybe you can help me analyze it, and tell me why it's not working correctly.

Link to comment
Share on other sites

On 11/1/2020 at 11:59 PM, BIGAL said:

Played with  Tins for over 40 years, points as a block is not a problem, if needed convert back to a 3d point. Or in civ3D etc can read a csv file direct and make a TIN.

 

If you want TINS what are you using to make them ?  Most Civil software has the options about labelling the points.

 

Have you looked at this http://lee-mac.com/ptmanager.html may be very useful.

Well I see I'm talking with someone REALLY experienced, And I hope someday I can have as much experience as Lee, I'm a big fan of him. And I know there might be some other options to look, but I want this to work and keep learning. Maybe I can copy some functions of Lee into my code. Thanks, I hope you can keep helping me out.

Link to comment
Share on other sites

2 hours ago, Isaac26a said:

Maybe you're totally right and I have some other error before on my code.

The error that I get is:

error: bad DXF group: (-3 ("urb_pt" (1000 . NUM) (1000 . DESCRIP) (1005 . 
THENUMBER) (1005 . THEELEVATION) (1005 . THEDESCRIPTION)))

An the code is the following

 

Do not delete the cons function. I don't understand why you did that with my previous sample.

 

(setq num "1")

 (cons 1000 num) -> (1000 . "1")
 (1000 . num)    -> bad syntax of function call: (1000 . NUM)
'(1000 . num)    -> (1000 . NUM)) 

As you can see, you cannot use quote here. The only valid list is the first one.

 

 

Use the following code without editing.

 

(setq data
          (list
            (list
              -3
              (list
                "urb_pt"
                 (cons 1000 num)         ;;; Point number
                 (cons 1000 descrip)     ;;; Description
                 (cons 1005 thenumber)     ;;; Assoc 5 of the text that holds the point number
                 (cons 1005 theelevation)     ;;; Assoc 5 of the text that holds the elevation
                 (cons 1005 thedescription)     ;;; Assoc 5 of the text that holds the description
              )
            )
          )
   )

 

Link to comment
Share on other sites

4 hours ago, Isaac26a said:

And I hope someday I can have as much experience as Lee, I'm a big fan of him.

 

Even if you make a substantial progress, you won't believe how far behind of him you'll be (and won't even imagine).

Talking from experience. 😉

 

Anyway, regarding to

4 hours ago, Isaac26a said:

The error that I get is:

error: bad DXF group: (-3 ("urb_pt" (1000 . NUM) (1000 . DESCRIP) (1005 . 
THENUMBER) (1005 . THEELEVATION) (1005 . THEDESCRIPTION)))

 

Read about his apostrophe and quote function tutorial.

...aand I've just learned now about the name of a certain technique (that I was wondering about) was called Run-time Evaluation...

Edited by Grrr
Link to comment
Share on other sites

23 hours ago, Stefan BMR said:

 

Do not delete the cons function. I don't understand why you did that with my previous sample.

 


(setq num "1")

 (cons 1000 num) -> (1000 . "1")
 (1000 . num)    -> bad syntax of function call: (1000 . NUM)
'(1000 . num)    -> (1000 . NUM)) 

As you can see, you cannot use quote here. The only valid list is the first one.

 

 

Use the following code without editing.

 


(setq data
          (list
            (list
              -3
              (list
                "urb_pt"
                 (cons 1000 num)         ;;; Point number
                 (cons 1000 descrip)     ;;; Description
                 (cons 1005 thenumber)     ;;; Assoc 5 of the text that holds the point number
                 (cons 1005 theelevation)     ;;; Assoc 5 of the text that holds the elevation
                 (cons 1005 thedescription)     ;;; Assoc 5 of the text that holds the description
              )
            )
          )
   )

 

Thanks Stefan, this time it Did worked all right, I'll keep in touch. You are as always right.

Link to comment
Share on other sites

21 hours ago, Grrr said:

 

Even if you make a substantial progress, you won't believe how far behind of him you'll be (and won't even imagine).

Talking from experience. 😉

 

Anyway, regarding to

 

Read about his apostrophe and quote function tutorial.

...aand I've just learned now about the name of a certain technique (that I was wondering about) was called Run-time Evaluation...

Thanks, I think I'll take all of your advices, Thanks for helping me.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...