Jump to content

COORDINATES REQUIRED AT START END AND MID OF LINES


Recommended Posts

Posted

Dear Friends,

I have a task where I have to assign coordinates to start, end and mid of lines. Each drawing has 11 lines for each for which I  need the coordinates at these locations and there are around 500 drawing.

Is there any way I can select all the lines and coordinates are plotted at the start, mid and end of the lines in one shot. Refer the drawing attached.

or is there any code which has some type of a block which can be inserted at these locations and the coordinate values are displayed as attributes and the blocks are exploded to get the results.

Kindly do the needful in getting the right and proper solution to solve this challenge.

MULTIPLE-COORDINATES.dwg

Posted (edited)

Try the attached. MText and Leader on layer "0" color ByLayer. Only selects lines.

 

lineIDs.lsp

Edited by dlanorh
  • Like 1
Posted

TEST THIS 

 

 

 



(defun c:test ( /  I LIX SS)

  (prompt "\nSelect  lines...")
  (setq ss (ssget '((0 . "LINE"))))
 
  (if ss
    (progn
      (repeat (setq i (sslength ss))
        (setq lix (entget (ssname ss (setq i (1- i)))))


        (entmakex
     (list (cons 0   "MTEXT")         
           (cons 100 "AcDbEntity")          
           (cons 100 "AcDbMText")    
           (cons 10 (cdr (assoc 10 lix)))
           (cons 71 5)
           (cons 40 5)
           (cons 50 0)
           (cons  1
                  (strcat (strcat "N=" (rtos (cadr (assoc 10 lix)) 2 4));; reversed north/east value
                          (strcat "\\PE=" (rtos (car (assoc 10 lix)) 2 4));; reversed north/east value
                          (strcat "\\PZ=" (rtos (caddr (assoc 10 lix)) 2 4))
                  )
                  )
     )
  )
        (entmakex
     (list (cons 0   "MTEXT")         
           (cons 100 "AcDbEntity")          
           (cons 100 "AcDbMText")    
           (cons 10 (mapcar (function (lambda (a b) (/ (+ a b) 2.0))) (cdr (assoc 10 lix)) (cdr (assoc 11 lix))))
           (cons 71 5)
           (cons 40 5)
           (cons 50 0)
           (cons  1
                  (strcat (strcat "N=" (rtos (cadr (mapcar (function (lambda (a b) (/ (+ a b) 2.0))) (cdr (assoc 10 lix)) (cdr (assoc 11 lix)))) 2 4));; reversed north/east value
                          (strcat "\\PE=" (rtos (car (mapcar (function (lambda (a b) (/ (+ a b) 2.0))) (cdr (assoc 10 lix)) (cdr (assoc 11 lix)))) 2 4));; reversed north/east value
                          (strcat "\\PZ=" (rtos (caddr (mapcar (function (lambda (a b) (/ (+ a b) 2.0))) (cdr (assoc 10 lix)) (cdr (assoc 11 lix)))) 2 4))
                  )
                  )
     )
  )
        (entmakex
     (list (cons 0   "MTEXT")         
           (cons 100 "AcDbEntity")          
           (cons 100 "AcDbMText")    
           (cons 10 (cdr (assoc 11 lix)))
           (cons 71 5)
           (cons 40 5)
           (cons 50 0)
           (cons  1
                  (strcat (strcat "N=" (rtos (cadr (assoc 11 lix)) 2 4));; reversed north/east value
                          (strcat "\\PE=" (rtos (car (assoc 11 lix)) 2 4));; reversed north/east value
                          (strcat "\\PZ=" (rtos (caddr (assoc 11 lix)) 2 4))
                  )
                  )
     )
  )

    
        
      )
      
      
    )
  )
  (princ)
)


 

Posted

Nice, I always do the lambda divide pts / 2 as 2 steps so thanks now 1 line.

 

I Work in metric rtos 2 4 that is to 1/10 of a mm 2 3 is the norm for a dwg in metres.

 

The next step would be to use Aeccoreconsole to process 500 dwg's

 

I would have used VL just a personal preference 

 

(setq lix (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
(setq start (vlax-get lix 'StartPoint))
(setq end (vlax-get lix 'EndPoint))
(setq mid (mapcar (function (lambda (a b) (/ (+ a b) 2.0))) start end))

 

Just a comment here in AUS E,N,Z depends where you are in the world.

 

 

  • Thanks 1
Posted
16 hours ago, dlanorh said:

Try the attached. MText and Leader on layer "0" color ByLayer. Only selects lines.

 

lineIDs.lsp 1.89 kB · 2 downloads

Thanks a lot to you for your help.

Greatly appreciate your efforts for this excellent code.

Posted
16 hours ago, hosneyalaa said:

TEST THIS 

 

 

 




(defun c:test ( /  I LIX SS)

  (prompt "\nSelect  lines...")
  (setq ss (ssget '((0 . "LINE"))))
 
  (if ss
    (progn
      (repeat (setq i (sslength ss))
        (setq lix (entget (ssname ss (setq i (1- i)))))


        (entmakex
     (list (cons 0   "MTEXT")         
           (cons 100 "AcDbEntity")          
           (cons 100 "AcDbMText")    
           (cons 10 (cdr (assoc 10 lix)))
           (cons 71 5)
           (cons 40 5)
           (cons 50 0)
           (cons  1
                  (strcat (strcat "N=" (rtos (cadr (assoc 10 lix)) 2 4));; reversed north/east value
                          (strcat "\\PE=" (rtos (car (assoc 10 lix)) 2 4));; reversed north/east value
                          (strcat "\\PZ=" (rtos (caddr (assoc 10 lix)) 2 4))
                  )
                  )
     )
  )
        (entmakex
     (list (cons 0   "MTEXT")         
           (cons 100 "AcDbEntity")          
           (cons 100 "AcDbMText")    
           (cons 10 (mapcar (function (lambda (a b) (/ (+ a b) 2.0))) (cdr (assoc 10 lix)) (cdr (assoc 11 lix))))
           (cons 71 5)
           (cons 40 5)
           (cons 50 0)
           (cons  1
                  (strcat (strcat "N=" (rtos (cadr (mapcar (function (lambda (a b) (/ (+ a b) 2.0))) (cdr (assoc 10 lix)) (cdr (assoc 11 lix)))) 2 4));; reversed north/east value
                          (strcat "\\PE=" (rtos (car (mapcar (function (lambda (a b) (/ (+ a b) 2.0))) (cdr (assoc 10 lix)) (cdr (assoc 11 lix)))) 2 4));; reversed north/east value
                          (strcat "\\PZ=" (rtos (caddr (mapcar (function (lambda (a b) (/ (+ a b) 2.0))) (cdr (assoc 10 lix)) (cdr (assoc 11 lix)))) 2 4))
                  )
                  )
     )
  )
        (entmakex
     (list (cons 0   "MTEXT")         
           (cons 100 "AcDbEntity")          
           (cons 100 "AcDbMText")    
           (cons 10 (cdr (assoc 11 lix)))
           (cons 71 5)
           (cons 40 5)
           (cons 50 0)
           (cons  1
                  (strcat (strcat "N=" (rtos (cadr (assoc 11 lix)) 2 4));; reversed north/east value
                          (strcat "\\PE=" (rtos (car (assoc 11 lix)) 2 4));; reversed north/east value
                          (strcat "\\PZ=" (rtos (caddr (assoc 11 lix)) 2 4))
                  )
                  )
     )
  )

    
        
      )
      
      
    )
  )
  (princ)
)


 

Hosneyalaa ; Thanks for your efforts in helping me appreciate your time and efforts. I get some errors in the answers look for the attached image for result and properties. 

image.png

Posted

i am sory  

updata lisp

 

 

 



(defun c:test ( /  I LIX SS)

  (prompt "\nSelect  lines...")
  (setq ss (ssget '((0 . "LINE"))))
 
  (if ss
    (progn
      (repeat (setq i (sslength ss))
        (setq lix (entget (ssname ss (setq i (1- i)))))


        (entmakex
     (list (cons 0   "MTEXT")         
           (cons 100 "AcDbEntity")          
           (cons 100 "AcDbMText")    
           (cons 10 (cdr (assoc 10 lix)))
           (cons 71 5)
           (cons 40 5)
           (cons 50 0)
           (cons  1
                  (strcat (strcat "N=" (rtos (cadr (cdr(assoc 10 lix))) 2 4));; reversed north/east value
                          (strcat "\\PE=" (rtos (car (cdr(assoc 10 lix))) 2 4));; reversed north/east value
                          (strcat "\\PZ=" (rtos (caddr (cdr(assoc 10 lix))) 2 4))
                  )
                  )
     )
  )
        (entmakex
     (list (cons 0   "MTEXT")         
           (cons 100 "AcDbEntity")          
           (cons 100 "AcDbMText")    
           (cons 10 (mapcar (function (lambda (a b) (/ (+ a b) 2.0))) (cdr (assoc 10 lix)) (cdr (assoc 11 lix))))
           (cons 71 5)
           (cons 40 5)
           (cons 50 0)
           (cons  1
                  (strcat (strcat "N=" (rtos (cadr (mapcar (function (lambda (a b) (/ (+ a b) 2.0))) (cdr (assoc 10 lix)) (cdr (assoc 11 lix)))) 2 4));; reversed north/east value
                          (strcat "\\PE=" (rtos (car (mapcar (function (lambda (a b) (/ (+ a b) 2.0))) (cdr (assoc 10 lix)) (cdr (assoc 11 lix)))) 2 4));; reversed north/east value
                          (strcat "\\PZ=" (rtos (caddr (mapcar (function (lambda (a b) (/ (+ a b) 2.0))) (cdr (assoc 10 lix)) (cdr (assoc 11 lix)))) 2 4))
                  )
                  )
     )
  )
        (entmakex
     (list (cons 0   "MTEXT")         
           (cons 100 "AcDbEntity")          
           (cons 100 "AcDbMText")    
           (cons 10 (cdr (assoc 11 lix)))
           (cons 71 5)
           (cons 40 5)
           (cons 50 0)
           (cons  1
                  (strcat (strcat "N=" (rtos (cadr (cdr(assoc 11 lix))) 2 4));; reversed north/east value
                          (strcat "\\PE=" (rtos (car (cdr(assoc 11 lix))) 2 4));; reversed north/east value
                          (strcat "\\PZ=" (rtos (caddr (cdr(assoc 11 lix))) 2 4))
                  )
                  )
     )
  )

    
        
      )
      
      
    )
  )
  (princ)
)

 

10 minutes ago, CADWORKER said:

Hosneyalaa ; Thanks for your efforts in helping me appreciate your time and efforts. I get some errors in the answers look for the attached image for result and properties. 

image.png

 

Posted

 

thank you sir  BIGAL
The code has been modified idea  sir  BIGAL
To reduce the time

thank you

6 hours ago, BIGAL said:

Nice, I always do the lambda divide pts / 2 as 2 steps so thanks now 1 line.

 

I Work in metric rtos 2 4 that is to 1/10 of a mm 2 3 is the norm for a dwg in metres.

 

The next step would be to use Aeccoreconsole to process 500 dwg's

 

I would have used VL just a personal preference 

 


(setq lix (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
(setq start (vlax-get lix 'StartPoint))
(setq end (vlax-get lix 'EndPoint))
(setq mid (mapcar (function (lambda (a b) (/ (+ a b) 2.0))) start end))

 

Just a comment here in AUS E,N,Z depends where you are in the world.

 

 



(defun c:test ( /  I LIX SS)

  (prompt "\nSelect  lines...")
  (setq ss (ssget '((0 . "LINE"))))
 
  (if ss
    (progn
      (repeat (setq i (sslength ss))
;;;        (setq lix (entget (ssname ss (setq i (1- i)))))


        (setq lix (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
        (setq start (vlax-get lix 'StartPoint))
         (setq end (vlax-get lix 'EndPoint))
         (setq mid (mapcar (function (lambda (a b) (/ (+ a b) 2.0))) start end))


        (entmakex
     (list (cons 0   "MTEXT")         
           (cons 100 "AcDbEntity")          
           (cons 100 "AcDbMText")    
           (cons 10 start)
           (cons 71 5)
           (cons 40 5)
           (cons 50 0)
           (cons  1
                  (strcat (strcat "N=" (rtos (cadr start) 2 4));; reversed north/east value
                          (strcat "\\PE=" (rtos (car start) 2 4));; reversed north/east value
                          (strcat "\\PZ=" (rtos (caddr start) 2 4))
                  )
                  )
     )
  )
        (entmakex
     (list (cons 0   "MTEXT")         
           (cons 100 "AcDbEntity")          
           (cons 100 "AcDbMText")    
           (cons 10 mid)
           (cons 71 5)
           (cons 40 5)
           (cons 50 0)
           (cons  1
                  (strcat (strcat "N=" (rtos (cadr mid) 2 4));; reversed north/east value
                          (strcat "\\PE=" (rtos (car mid) 2 4));; reversed north/east value
                          (strcat "\\PZ=" (rtos (caddr mid) 2 4))
                  )
                  )
     )
  )
        (entmakex
     (list (cons 0   "MTEXT")         
           (cons 100 "AcDbEntity")          
           (cons 100 "AcDbMText")    
           (cons 10 end)
           (cons 71 5)
           (cons 40 5)
           (cons 50 0)
           (cons  1
                  (strcat (strcat "N=" (rtos (cadr end) 2 4));; reversed north/east value
                          (strcat "\\PE=" (rtos (car end) 2 4));; reversed north/east value
                          (strcat "\\PZ=" (rtos (caddr end) 2 4))
                  )
                  )
     )
  )

    
        
      )
      
      
    )
  )
  (princ)
)

 

Posted
10 hours ago, hosneyalaa said:

 

 


;;;        (setq lix (entget (ssname ss (setq i (1- i)))))

        (setq lix (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
        (setq start (vlax-get lix 'StartPoint))
         (setq end (vlax-get lix 'EndPoint))

 

 

There is no need to convert the entity to vla-object to retrieve data in this case at all and as you already did in the first post but you did not assign the start & end coordinates to variables as in the last reply you posted.

The following is enough.

 (setq lix (entget (ssname ss (setq i (1- i)))))
 (setq start (cdr (assoc 10 lix)))
 (setq end   (cdr (assoc 11 lix)))

 

  • Thanks 1

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...