Jump to content

Selection of Text to Fields in a Table


Mattinahat

Recommended Posts

First, I was wondering where I can start to understand more about lisp? I've gone through the tutorial on the main website, but I was hoping to be pointed to more information. I love posting and just getting an answer, but I would like to contribute more. I want to have a half working script and troubleshoot and learn. Where can I find out more about lisp? I figured I'd ask the people who know the most and are amazing at coding! :)

 

Now to my actual question:

I'm trying to devise a lisp file that will sort a group of text. Basically, I need to highlight a bunch of text and have it filled into a table as fields. For example, if I have "1", "2", "3", and "4" as my text, after highlighting it, a field would appear in the left hand column of the table linked to those texts. Is this possible?

 

Thanks so much for everyones help!

-Mattinahat

Link to comment
Share on other sites

Hi,

 

This will allow the user to place a text string from Text, MText or Attribute as a field in a table cell.

 

(defun c:t2cell ( / doc tables ent pt )
 ;; © Lee Mac  ~  25.05.10
 (vl-load-com)

 (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

 (if (setq tables (ss->vla (ssget "_X" '((0 . "ACAD_TABLE")))))    
   (while
     (setq ent
       (SelectifFoo
         (lambda ( x )
           (wcmatch (cdr (assoc 0 (entget x))) "TEXT,MTEXT,ATTRIB")
         )
         "\nSelect Text, MText, or Attrib: "
       )
     )
     (while
       (and (setq pt (getpoint "\nPick Cell to Place Text: "))
         (not
           (TextinCell tables pt
             (strcat "%<\\AcObjProp Object(%<\\_ObjId "
               (GetObjectID (vlax-ename->vla-object ent) doc) ">%).TextString>%"
             )
           )
         )
       )
       (princ "\n** No Cell Found **")
     )
   )
   (princ "\n** No Tables in Drawing **")
 )
 (princ)
)


(defun SelectifFoo ( foo str / sel ent )
 (while
   (progn
     (setq sel (nentsel str))
     
     (cond
       (
         (vl-consp sel)

         (if (not (foo (setq ent (car sel))))
           (princ "\n** Invalid Object Selected **")
         )
       )
     )
   )
 )
 ent
)

(defun TextinCell ( tables pt str / data )
 ;; © Lee Mac  ~  17.05.10
 (if
   (setq data
     (vl-some
       (function
         (lambda ( table )
           (if
             (eq :vlax-true
               (vla-hittest table (vlax-3D-point (trans pt 1 0))
                 (vlax-3D-point (trans (getvar 'VIEWDIR) 1 0)) 'row 'col
               )
             )
             (list table row col)
           )
         )
       )
       tables
     )
   )
   (not (apply (function vla-setText) (append data (list str))))
 )
)

(defun ss->vla ( ss )
 (if ss
   (
     (lambda ( i / e l )
       (while (setq e (ssname ss (setq i (1+ i))))
         (setq l (cons (vlax-ename->vla-object e) l))
       )
       l
     )
     -1
   )
 )
)

(defun GetObjectID ( obj doc )
 (if (eq "X64" (strcase (getenv "PROCESSOR_ARCHITECTURE")))
   (vlax-invoke-method (vla-get-Utility doc) 'GetObjectIdString obj :vlax-false)
   (itoa (vla-get-Objectid obj))
 )
)

Link to comment
Share on other sites

wow, I dont know how you do it! Would you be able to teach me? Or point the way to where I can learn?

 

Also, if you don't mind, I have one tweak request if it is possible. Instead of individually selecting fields and cells, is there a way to select multiple texts, click the first cell, and the texts fill top to bottom?

 

Thanks for your time and amazing codes!

Link to comment
Share on other sites

Thanks - its just practice with a bit of educated risk taking :)

 

As for the program, I want to keep it as generic as possible so that most members can make use of it, and also, how would it know in which order to place the fields with multiple selection anyway?

Link to comment
Share on other sites

hmm good point; maybe it can sort it alphanumerically? I'll think about it a bit more, but I understand keeping it general; its definitely a great script!

 

When you started learning lisp, did you use a book? I guess I'm looking for some kind of catalyst to push me through the learning curve, ha.

Link to comment
Share on other sites

When you started learning lisp, did you use a book? I guess I'm looking for some kind of catalyst to push me through the learning curve, ha.

 

To get the very very basics, I used the Jeffrey Sanders site - just to learn the list manipulation. But the rest I learned from examples posted on the forums. As you get better at it, you start to see quicker ways of doing things, and cleaner solutions.

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