See the top rated post in this thread. Click here

Results 1 to 9 of 9

Thread: How to use "entsel" to extract part of string

  1. #1
    Member
    Join Date
    2006-04
    Posts
    3
    Login to Give a bone
    0

    Default How to use "entsel" to extract part of string

    I have a string "3.36+4.67+7.04+9.85-9.14=34.06"
    How to use "entsel" in the "4.67" nearby and extract "4.67" out?
    Any help would be greatly apprieciated!

  2. #2
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,105
    Login to Give a bone
    0

    Default Re: How to use "entsel" to extract part of string

    If it is a string, you would use the substr function, not entsel. However, if you need to first select an object that contains that string, you would use the entsel function first.

    The entsel function returns a list. The first element of the list is the entity name of the object selected. The second element is the point the user picked. However, if the user misses an object when selecting, the function returns nil. This means you will need to verify the returned value is not nil before you start requesting data out of the returned value.

    You can select the first item, which is the entity name, in the list using the car function. Once you have the entity name, you can either go the straight AutoLISP path or move over to the Visual LISP path to get the text string.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  3. #3
    Member
    Join Date
    2006-04
    Posts
    3
    Login to Give a bone
    0

    Default Re: How to use "entsel" to extract part of string

    I want to use "entsel" function (the point-second element of the retunn list)

    to pick the part of string,may be the point is at the "9.85" nearby and extract "9.85" out

  4. #4
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,105
    Login to Give a bone
    0

    Default Re: How to use "entsel" to extract part of string

    Are you thinking of the cadr function? That will return the second element in a list. It will not return the second number in a string.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  5. #5
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    1

    Default Re: How to use "entsel" to extract part of string

    Give this a try:

    Code:
    (defun c:FOO (/ BB:Parser ss)
    
      (defun BB:Parser (char string / i segments segment)
        ;; Example: (BB:Parser "-" "dd-mm-yyyy")
        ;; Returns: ("dd" "mm" "yyyy")
        (while (setq i (vl-string-search char string))
          (setq segments (cons (setq segment (substr string 1 i)) segments))
          (setq string (substr string (+ 2 i)))
        )
        (reverse (cons string segments))
      )
    
      (if
        (and
          (princ "\nSelect text to extract second real number: ")
          (setq ss (ssget ":S:E" '((0 . "MTEXT,TEXT") (1 . "*#*+*#*=*#*"))))
        )
         (prompt
           (strcat "\nThe second real number is: "
    	       (cadr (BB:Parser	"+"
    				(cdr (assoc 1
    					    (entget (ssname ss 0))
    				     )
    				)
    		     )
    	       )
           )
         )
      )
      (princ)
    )
    Last edited by BlackBox; 2014-04-30 at 05:36 PM.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  6. #6
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: How to use "entsel" to extract part of string

    Quote Originally Posted by afacad View Post
    I want to use "entsel" function (the point-second element of the retunn list)

    to pick the part of string,may be the point is at the "9.85" nearby and extract "9.85" out
    I couldve sworn CAB at the swamp wrote a program with this capability, but it would be fun to code though.

  7. #7
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    1

    Default Re: How to use "entsel" to extract part of string

    Maybe this simple code can help you for a start...

    Code:
    (defun c:pickchar ( / e p el ip txt k char )
      (while (not (eq (cdr (assoc 0 (entget (car (setq e (entsel "\nPick char inside text entity")))))) "TEXT")))
      (setq p (cadr e))
      (setq el (entget (car e)))
      (setq ip (cdr (assoc 10 el)))
      (setq txt (cdr (assoc 1 el)))
      (setq k 0)
      (while (< (+ (car ip) (car (cadr (textbox (subst (cons 1 (substr txt 1 (setq k (1+ k)))) (assoc 1 el) el))))) (car p)))
      (setq char (substr txt k 1))
      (terpri)
      (prompt (strcat "\n\"" char "\""))
      (princ)
    )

  8. #8
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: How to use "entsel" to extract part of string

    Quote Originally Posted by marko_ribar View Post
    Maybe this simple code can help you for a start...

    Code:
    (defun c:pickchar ( / e p el ip txt k char )
      .......
    Nice idea Marko

    Here's a quick mod to accommodate the OP's request
    How to use "entsel" in the "4.67" nearby and extract "4.67" out?
    Code:
    (defun c:pickchar ( / e p el ip txt k char )
      (while (not (eq (cdr (assoc 0 (entget (car (setq e (entsel "\nPick char inside text entity")))))) "TEXT")))
      (setq p (cadr e))
      (setq el (entget (car e)))
      (setq ip (cdr (assoc 10 el)))
      (setq txt (cdr (assoc 1 el)))
      (setq k 0)
      (while (< (+ (car ip) (car (cadr (textbox (subst (cons 1 (substr txt 1 (setq k (1+ k)))) (assoc 1 el) el))))) (car p)))
      (setq char (substr txt k 1))
      (while (and (setq nxt (substr txt (setq k (1+ k)) 1))
        	      (and (/= (ascii nxt) 47)(< 45 (ascii nxt)  58)))
      (setq char (strcat char nxt)))
      (terpri)
      (prompt (strcat "\n\"" char "\""))
      (princ)
    )
    Granting the user select the first number of the target value. i.e 4 of 4.67 and not "6", "7" or even "."

  9. #9
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: How to use "entsel" to extract part of string

    Have time to kil....

    Code:
    (defun c:pickchar (/ _allowed  _track  e p el ip txt k char pr sf)
    (defun _allowed (n)(and (/= n 47) (< 45 n 58)))
    (defun _track (str ch sym n / nxt)
      (while (and  (setq n (sym n))
    	       (> n 0)
    	      (setq nxt (substr str n 1))
    	      (_allowed (Ascii nxt))
    	 )
        (setq ch (if (eq 1+ sym) (strcat ch nxt)(strcat nxt ch)))
        
      )
      ch
    )  
      (while
        (not
          (eq (cdr
    	    (assoc
    	      0
    	      (entget
    		(car (setq e (entsel "\nPick char inside text entity")))
    	      )
    	    )
    	  )
    	  "TEXT"
          )
        )
      )
      (setq p (cadr e))
      (setq el (entget (car e)))
      (setq ip (cdr (assoc 10 el)))
      (setq txt (cdr (assoc 1 el)))
      (setq k 0)
      (while
        (< (+ (car ip)
    	  (car
    	    (cadr
    	      (textbox (subst (cons 1 (substr txt 1 (setq k (1+ k))))
    			      (assoc 1 el)
    			      el
    		       )
    	      )
    	    )
    	  )
           )
           (car p)
        )
      )
      (setq char (substr txt k 1))
      (setq char 
      (if (_allowed (ascii char))
      (strcat 
      	(if (/= char (setq pr (_track txt char 1- k))) pr char)
    	(if (/= char (setq sf (_track txt char 1+ k))) (substr sf 2) ""))
        char)
    	)
      (terpri)
      (prompt (strcat "\n\"" char "\""))
      (princ)
    )
    <Not Thoroughly tested> [i'll come back tomorrow to improve the coding]

Similar Threads

  1. 2015: "make part" or "derive"...which is better?
    By No more AUGI for me. in forum Inventor - General
    Replies: 8
    Last Post: 2014-08-01, 08:25 AM
  2. 2014: "Edit in Storm and Sanitary Analysis" will not Extract My Network....
    By aspencer.226869 in forum AutoCAD Civil 3D - Pipes
    Replies: 0
    Last Post: 2014-05-09, 05:35 PM
  3. Replies: 2
    Last Post: 2009-05-19, 05:40 PM
  4. What's the .ini string to turn "copy multiple" on by default?
    By cstanley in forum Revit Architecture - General
    Replies: 4
    Last Post: 2008-09-23, 12:18 PM
  5. URGENT! "Extract Quantities From A Revit Model."
    By dtownsend in forum Revit Architecture - General
    Replies: 7
    Last Post: 2006-06-29, 01:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •