Jump to content

Recommended Posts

Posted

Ok so for ages I have used a LISP called TXT2PT by Lee Mac to create 3d points from text to enable me to draw up cross sections from dodgy imported pdf's.

I only do this cus if i ask for the cad file in 3d the world would have collapsed into a playdough ball by the time client responds and its only for budget pricing.

 

My problem is for no reason other than, that's how we have done it for the past 30 years, is we work in millimeters not metres. This means i have to scale my

plan covered in lovely levels down by 100 before performing the TXT2PT lisp, then scale it back up to align with everything else... yes i am waffling but bear with me.

 

I have googled the crap out of how to times the Z value taken from the text before placing the point at the Z value and i admit i am being a bit thick or whomever

came up with LISP files is an alien...

 

So basically i if the text says 25.466 i need the point to be placed at 25466... If anyone can help and explain to me briefly how the additional text would affect the lisp

i will hold the door open for when or where ever we meet.........

 

Cheers Paul

txt2pt.LSP

Posted (edited)

Try this - not tested:

(defun c:txt2pt (/ Point i ss ent pt)

  (defun Point (pt) (entmakex (list (cons 0 "POINT") (cons 10 pt))))

  (if (setq i -1 ss (ssget '((0 . "TEXT,MTEXT"))))
    (while (setq ent (ssname ss (setq i (1+ i))))
      ;;(setq pt (cdr (assoc 10 (entget ent * 1000)))) ; <-- Syntax incorrect!
      (setq pt (* (caddr (cdr (assoc 10 (entget ent)))) 1000)) ; Pull Z coordinate from point list then multiply.
      (Point (list (car pt) (cadr pt)
                   (cond ((distof (cdr (assoc 1 (entget ent))))) (0))))
    )
  )

  (princ))

 

Edited by pkenewell
Posted

Maybe using a mapcar approach can multiply X Y & Z in one go. Can use any multiplier value for any of X Y Z, eg 1 1 1000.0

 

(setq pt (mapcar '* pt '(1000. 1000. 1000. )))

 

Posted
20 hours ago, pkenewell said:

Try this - not tested:

(defun c:txt2pt (/ Point i ss ent pt)

  (defun Point (pt) (entmakex (list (cons 0 "POINT") (cons 10 pt))))

  (if (setq i -1 ss (ssget '((0 . "TEXT,MTEXT"))))
    (while (setq ent (ssname ss (setq i (1+ i))))
      ;;(setq pt (cdr (assoc 10 (entget ent * 1000)))) ; <-- Syntax incorrect!
      (setq pt (* (caddr (cdr (assoc 10 (entget ent)))) 1000)) ; Pull Z coordinate from point list then multiply.
      (Point (list (car pt) (cadr pt)
                   (cond ((distof (cdr (assoc 1 (entget ent))))) (0))))
    )
  )

  (princ))

 

Thank you for that but i get an error.


; error: bad argument type: consp 0.0

Posted
14 hours ago, BIGAL said:

Maybe using a mapcar approach can multiply X Y & Z in one go. Can use any multiplier value for any of X Y Z, eg 1 1 1000.0

 

(setq pt (mapcar '* pt '(1000. 1000. 1000. )))

 

Sorry, being as thick as i am, where in the lisp do i place this text ?

 

Posted
1 hour ago, PaulyPHI said:

Sorry, being as thick as i am, where in the lisp do i place this text ?

OK - please be clear: Do you need the X,Y, and Z scaled, or only the Z? BIGAL's solution scales all the coordinates.

Did you try my solution?

Posted (edited)
2 hours ago, PaulyPHI said:

Thank you for that but i get an error.


; error: bad argument type: consp 0.0

@PaulyPHI

OK - Sorry it looks like you are trying to get the Z value from a text object's string, then transfer it to a Point object?

Try This:

(defun c:txt2pt (/ Point i ss ent pt)

  (defun AddPoint (pt) (entmakex (list (cons 0 "POINT") (cons 10 pt))))

  (if (setq i -1 ss (ssget '((0 . "TEXT,MTEXT"))))
    (while (setq ent (ssname ss (setq i (1+ i))))
      (setq pt (cdr (assoc 10 (entget ent)))
            pt (list (car pt) (cadr pt) (* 1000 (cond ((distof (cdr (assoc 1 (entget ent))))) (0.0))))
      )
      (Addpoint pt)
    )
  )
  (princ)
)

NOTE: you should not make a function the same name as a command, so I changed the "Point" sub-function to "Addpoint".

Edited by pkenewell
Posted

@pkenewell thank you for that, it works perfectly.... 

 

One day i will understand how lisp language works, then i will retire and never use it again 😁

  • Like 1
Posted

Just adjusted your code quickly, holiday day for me so no testing (CAD is off you see)

 

As pkenewell suggests to rename the function Point to something else, I would usually use 'MakePoint' - up to you to change that

 

Adjusted the (setq pt... line, (entget ent * 1000) won't work - if you do a (princ (entget ent)) you'll see why

Mapcar is a fantastic tool for list manipulation, below multiplying the point by 1000 x, y, z. '* is the function you are applying, could equally be '+ '- and so on, remembering the ' . the next list is what you are applying this function to the last list, here *1000, *1000, *1000 to the first 3 items in pt. Of course, you can set these to 1 (so that the value stays the same) and with * to 0 to set the x, y or z to the origin (so mapcar '* '(1 1 0) pt will set the point to 0 z value)

 

Just added in also where functions close, such as 'end while' 'end if' only a small LISP here but always handy in larger routines to keep track of what is happening where

 

 

 

(defun c:txt2pt ( / Point i ss ent pt)
  (defun Point ( pt / )
    (entmakex (list (cons 0 "POINT") (cons 10 pt)))
  ) ;; End Defun
  (if (setq i -1 ss (ssget '((0 . "TEXT,MTEXT"))))
    (while (setq ent (ssname ss (setq i (1+ i))))
;;      (setq pt (cdr (assoc 10 (entget ent * 1000))))

(setq pt (cdr (assoc 10 (entget ent))))
(setq pt (mapcar '* '(1000 1000 1000) pt)))

      (Point (list (car pt) (cadr pt)
                   (cond ((distof (cdr (assoc 1 (entget ent))))) (0))))
    ) ; end while
  ) ; end if
  (princ)
)

 

Posted (edited)

@Steven P That is a good academic exercise to learn from, but the OP did not want to scale all the location coordinates of the text. He wanted the X and Y straight from the text location without scaling, then using the VALUE in the text to get the Z coordinate multiplied by 1000 (Meters to Millimeters). I.e. if the text object is located at X=1200, Y=700, and the Value in the text is "10.4", the point would be located at X=1200, Y=700, and Z=10400.

Edited by pkenewell
  • Like 1
Posted

I would try to use the lisp as it is. Convert all the points to a block and change the scale in Z dirrection. 

...not tested...

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