looking to click on 5 points and output thier x and y cordinates to a table

looking to click on 5 points and output thier x and y cordinates to a table

AutoMarcus
Collaborator Collaborator
869 Views
5 Replies
Message 1 of 6

looking to click on 5 points and output thier x and y cordinates to a table

AutoMarcus
Collaborator
Collaborator

hi all

I am looking to make a block or lisp to simplify a process, hoping someone may have a great idea.

 

i am looking for a simple way to click on five points (outrigger legs of a crane plus the center) to output these coordinates to a table.

 

the points would be in model space, the table would be paper space

 

any ideas would be most appreciated.

cheers

0 Likes
870 Views
5 Replies
Replies (5)
Message 2 of 6

Sea-Haven
Mentor
Mentor

A couple of different ways 

 

Make a list of xyz points then go to paperspace and change the cell values or make table.

 

Just get the table as an object using vl, then change to model and settext the table, worked for me, I did not try say addrows so can pick as many points as you want.

 

Use Chspace

0 Likes
Message 3 of 6

AutoMarcus
Collaborator
Collaborator

thanks, some of this has gone straight over my head.

the vl (visual lisp) part i have no idea where to start

0 Likes
Message 4 of 6

CodeDing
Advisor
Advisor

@AutoMarcus ,

 

Here's a start. Nobody really likes formatting tables, but that's probably what you'll have to do to tweak this code and finalize it. Give this a go:

(defun c:TEST ( / tmp layoutName ptCenter ptsLegs len ptTbl acDoc pSpace tbl headers)
(vl-load-com)
(setq layoutName "Layout1") ;<-- this is name of your layout for table
;Initial Check(s)
(cond
  ((not (eq "Model" (getvar 'CTAB)))
    (setq tmp "\nMust be in Model Space to run command.") (prompt tmp) (alert tmp) (exit))
  ((not (member (strcase layoutName) (mapcar 'strcase (layoutlist))))
    (setq tmp (strcat "Layout '" layoutName "' can not be found.")) (prompt tmp) (alert tmp) (exit))
);cond
;Get inputs from user
(initget 1) (setq ptCenter (getpoint "\nSelect CENTER point: "))
(setq tmp 0)
(repeat (setq ptsLegs '() len 4)
  (initget 1)
  (setq ptsLegs (cons (getpoint (strcat "\nSelect LEG " (itoa (setq tmp (1+ tmp))) " of " (itoa len) ": ")) ptsLegs))
);repeat
(setq ptsLegs (reverse ptsLegs))
;Go to layout and create table
(setvar 'CTAB layoutName)
(initget 1) (setq ptTbl (vlax-3D-point (getpoint "\nSelect Upper-Left for table: ")))
(setq acDoc (vla-get-activedocument (vlax-get-acad-object))
      pSpace (vla-get-paperspace acDoc))
(setq tbl (vla-addtable pSpace ptTbl 7 3 0.5 2));row/col/rowHt/colWid
;Add text to table
;---Headers
(vla-settext tbl 0 0 "CRANE POINTS");row/col/string
(setq tmp -1 headers '("POINT NAME" "X COORD" "Y COORD"))
(repeat (setq len (length headers))
  (vla-settext tbl 1 (setq tmp (1+ tmp)) (nth tmp headers));row/col/string
);repeat
;---Center
(vla-settext tbl 2 0 "CENTER");row/col/string
(vla-settext tbl 2 1 (rtos (car ptCenter) 2 2));row/col/string --- RTOS determines units/precision
(vla-settext tbl 2 2 (rtos (cadr ptCenter) 2 2));row/col/string --- RTOS determines units/precision
;---Legs
(repeat (setq tmp -1 len (length ptsLegs))
  (vla-settext tbl (+ 3 (setq tmp (1+ tmp))) 0 (strcat "LEG " (itoa (1+ tmp))));row/col/string
  (vla-settext tbl (+ 3 tmp) 1 (rtos (car (nth tmp ptsLegs)) 2 2));row/col/string --- RTOS determines units/precision
  (vla-settext tbl (+ 3 tmp) 2 (rtos (cadr (nth tmp ptsLegs)) 2 2));row/col/string --- RTOS determines units/precision
);repeat
;Finish up
(prompt "\nComplete.")
(princ)
);defun

Also, here is a pretty bare-bones example of setting text height, adjusting alignment, etc.:

https://adndevblog.typepad.com/autocad/2012/04/autolisp-example-create-a-table-using-activex.html

 

Best,

~DD

0 Likes
Message 5 of 6

CodeDing
Advisor
Advisor

I guess I didn't even ask, but will the table be pre-existing? Already on the layout sheet? That would remove having to format via lisp.

0 Likes
Message 6 of 6

Sea-Haven
Mentor
Mentor

CodeDing, just me I would start in correct layout and like you does table exist yes / no if no (defun maketable), yes VL pick table set to same name as maketable then settext will work even from Model space or it least it did in 5 minutes of my testing. As you pick point can populate the table.

 

Just a side comment works with blocks using Block name & an attribute key can pick points in model and Block in a layout is updated. eg Blk name "Drain", key is "Pit2" 

 

5 points, 20 points use Addtablerow.

0 Likes