Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Making A Lisp that Ill insert a Table with the S.O.P Points

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
alex_mcturk
258 Views, 2 Replies

Making A Lisp that Ill insert a Table with the S.O.P Points

I hope I can explain this,

 

I have a lisp that when I select a point it will insert a block and Mtext with the S.O.P. name and then the X and why Coordinates, (this is the Co-Ords.lsp) this works well and as I wanted.

 

But my problem is that I can't seem to work out how can make a lisp that would take the Co-Ordinates that I have produce and provide a table.

 

EG.

Name   | X-Coordinate   |   Y-Coordinate

_______________________________

S.O.P 1 |                   156   |               500

_______________________________

S.O.P 2 |                   600  |               750

_______________________________

S.O.P 3 |                   186   |               900

 

 

I will only ever need 3 Columns, but my rows might vary by how many S.O.P points I have selected.

 

 

I have attached My lisp and the block I want to insert

2 REPLIES 2
Message 2 of 3
komondormrex
in reply to: alex_mcturk

row 0 is the table title, so you need to start from row 1 (header) (lines 33 and 44, 45, 46)

you have already strings in x and y (lines 55, 56) .

check the following.

 

 

(defun c:CreateCoOrdTable ()
  (if (not sop-list)
      (progn
          (princ "\nError: No S.O.P. points have been created.")
          (princ)
      )
    (progn
      (setq acadObj (vlax-get-Acad-Object))
      (setq activeDocument (vla-get-ActiveDocument acadObj))
      (setq curspace (vla-get-ModelSpace activeDocument))

      (if (not curspace)
          (progn
              (princ "\nError: Unable to get current space.")
              (princ)
          )
        (progn
          ;; Prompt the user to select a point for the top left corner of the table
          (setq pt1 (getpoint "\nPick point for top left hand of table: "))
          ;; Print out the value returned by getpoint
          (princ (strcat "\nValue returned by getpoint: " (vl-princ-to-string pt1)))
          ;; Check if a point is selected
          (if (not pt1)
              (progn
                  (princ "\nNo point selected for the table.")
                  (princ)
              )
            (progn
              ;; Convert the point to a suitable format for AutoLISP/VL functions
              (setq pt1 (vlax-3d-point pt1))

              ;; Define the number of rows and columns in the table
              (setq numrows (+ (length sop-list) 2)) ; Add 2 for the header row
              (setq numcolumns 3) ; Name, X, Y

              ;; Define the row height and column width
              (setq rowheight 4.5)
              (setq colwidth 40)

              ;; Add the table to the drawing
              (setq objtable (vla-addtable curspace pt1 numrows numcolumns rowheight colwidth))

              ;; Set the header row
              (vla-settext objtable 1 0 "Name")
              (vla-settext objtable 1 1 "X-Coordinate")
              (vla-settext objtable 1 2 "Y-Coordinate")

              ;; Populate the table with S.O.P. data
              (setq row 2)
              (foreach coord sop-list
                  (setq sop-name (car coord))
                  (setq x (cadr coord))
                  (setq y (caddr coord))
                  (vla-settext objtable row 0 sop-name)
                  (vla-settext objtable row 1 x) ;(rtos x 2 2))
                  (vla-settext objtable row 2 y) ;(rtos y 2 2))
                  (setq row (1+ row))
              )

              (princ "\nS.O.P. points table created successfully.")
              (princ)
            )
          )
        )
      )
    )
  )
)

 

 

Message 3 of 3
alex_mcturk
in reply to: komondormrex

Thank you that works perfectly

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report