Author Topic: Selecting an item after running executescript.  (Read 1399 times)

0 Members and 1 Guest are viewing this topic.

Offline CerrylTopic starter

  • Active Member
  • **
  • Posts: 14
  • Country: us
  • Gender: Male
Selecting an item after running executescript.
« on: Nov 06, 2018, 20:14:58 PM »
I have a lisp that I've been working on that runs multiple COD scripts on an object during the routine but I have to keep selecting the object after each executescript. I've worked around this by using pselect repeatedly throughout the lisp. I want it to work on a per object basis after selecting more than one object. It works great if everything you select needs the same information, but if I need to pull/push back different information it doesnt. It just pulls the info from the last item selected and gives them all that information.

I've tried using selection sets but because it deselects after each executescript, I just can't figure it out.

Code: [Select]
(defun c:replacevavtags(/ *error*)
;;error handling
  (defun *error* (msg)
    (and *AcadDoc* (vla-endundomark *AcadDoc*))
    (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
      (princ (strcat "\nError: " msg))
    )
    (close nfile)
    (close ofile)
    (close j)
  )
    (setq size (getvar 'textsize))
;; set object and get layer name
(setq e (ssname (ssget) 0))
(setq vlaobj (vlax-ename->vla-object e))
(setq layername (vlax-get-property vlaobj 'layer))
;; end set
(COMMAND "PSELECT" "P" "")
(executescript "X:/Design Aids/scripts/cdback.cod")
(COMMAND "PSELECT" "P" "")
(setq
ofile (open "c:\\text files\\textw.txt" "r")
nfile (open "c:\\text files\\textn.txt" "w")
j (open "c:\\text files\\textr.txt" "w")
)
;; start count of lines (ignores empty lines)
(setq count 1)
(while (setq aline (read-line ofile))
        (if (/= aline "")
           (setq count (1+ count))
        )
       )
(setq Nu1 (itoa count))
(write-line NU1 j)
(setq count (1- count))
(close j)
;; end count of lines
;; start ask if replace or not
(initget "Y N  _Y N")
(setq option (getkword "\nDo you want to change the tag? (Y/N): "))
(cond ((= option "Y")
;; start replace text
(initget "Y N  _Y N")
(setq option (getkword "\nDo you want to change the number of lines? (Y/N): "))
(cond ((= option "Y")
    (progn
(cond
((= (wcmatch layername "*EQPM*") T)
(progn
(while
(and
(progn
                  (initget 6)
                  (setq count2 (getint "\How many lines for EQ tag? (1 - 4)"))
  (setq count count2)
)
(not (wcmatch (itoa count2) "[1-4]"))
    )
          (princ "\nCan't be less than 1 or more than 4.")
    ))
)
(t
(progn
(while
(and
(progn
                  (initget 6)
                  (setq count2 (getint "\How many lines for tag? (1 - 5)"))
  (setq count count2)
)
(not (wcmatch (itoa count2) "[1-5]"))
    )
          (princ "\nCan't be less than 1 or more than 5.")
    ))
    )
)
)
    )
  ((= option "N") (setq count2 count))
)
    (vl-file-delete "c:\\text files\\textr.txt")
    (setq j (open "c:\\text files\\textr.txt" "w"))
    (setq count count2)
    (setq count3 (1+ count))
    (setq Nu1 (itoa count3))
    (write-line NU1 j)
(while (>= count3 2)
        (/= (setq inpNew (getstring t "\nEnter new line: ")) "")
(write-line inpNew nfile)
(setq count3 (1- count3))
)
(close nfile)
(close ofile)
(close j)
;; end replace text
)
)

;; start replace vav tag
(vl-file-delete "c:\\text files\\textw.txt")
(vl-file-rename "c:\\text files\\textn.txt" "c:\\text files\\textw.txt")
(command "removectext")
(COMMAND "PSELECT" "P" "")
(executescript "X:/Design Aids/scripts/entry.cod")
(COMMAND "PSELECT" "P" "")
(setq k (open "c:\\text files\\textr.txt" "r"))
(setq l (read-line k))     
(COMMAND "PSELECT" "P" "")
  (cond
((= size 4.0)
(prompt "\n Textsize is 1/4")
(cond
((= (wcmatch layername "*EQPM*") T)
(progn
(if (= l "5") (ctext "term5"))
(if (= l "4") (ctext "term4"))
(if (= l "3") (ctext "term3"))
(if (= l "2") (ctext "term2"))
(if (= l "1") (ctext "term1"))
))
(t
(if (= l "6") (ctext "entry5"))
(if (= l "5") (ctext "entry4"))
(if (= l "4") (ctext "entry3"))
(if (= l "3") (ctext "entry2"))
(if (= l "2") (ctext "entry1"))
)
)
)

((= size 8.0)
(prompt "\n Textsize is 1/8")
(cond
((= (wcmatch layername "*EQPM*") T)
(progn
(if (= l "5") (ctext "96term5"))
(if (= l "4") (ctext "96term4"))
(if (= l "3") (ctext "96term3"))
(if (= l "2") (ctext "96term2"))
(if (= l "1") (ctext "96term1"))
))
(t
(if (= l "6") (ctext "96entry5"))
(if (= l "5") (ctext "96entry4"))
(if (= l "4") (ctext "96entry3"))
(if (= l "3") (ctext "96entry2"))
(if (= l "2") (ctext "96entry1"))
)
)

)
(T (prompt "\nNeither 1/4 nor 1/8 Scale"))
    );cond
(settext(ssget)64"on")

(close k)
(close nfile)
(close ofile)
(close j)
(close fn)
;; end replace vav tag

;; clean up folder
    (vl-file-delete "c:\\text files\\textw.txt")
    (vl-file-delete "c:\\text files\\textr.txt")
;; end clean up folder

  (princ)
)

Offline Darren Young

  • Premier Member
  • *****
  • Posts: 2081
  • Country: us
  • Gender: Male
    • BIM There Done That.
Re: Selecting an item after running executescript.
« Reply #1 on: Nov 06, 2018, 20:31:49 PM »
Not following what the issue is.

So, you want to make a selection set (multiple objects) and loop through running a set of COD scripts on each item in the selection set?

Also, what's PSELECT do? Is that a function you've defined?

What do you mean by push/pulling information?  Does it need to read from one ITM and put the information into another?

Can you explain what the entire program is trying to do? That would help instead of having to reinterpret code as you know it better than me.


Offline DotNet

  • Senior Member
  • ****
  • Posts: 302
  • Country: us
  • Gender: Male
    • MICLOGIC
Re: Selecting an item after running executescript.
« Reply #2 on: Nov 07, 2018, 00:43:35 AM »
PSELECT P selects your previous selection set.

We need to loop through the selection set and create a new selection set for each individual object. I would use one script if at all possible, but you can reselect the entity after each script with (_Select ss).

Code: [Select]
(setq ss (ssadd e))...

(_Select ss)...

or...

Code: [Select]
Select !ss

at the command line.
« Last Edit: Nov 07, 2018, 02:03:00 AM by DotNet »

Offline cadragon

  • Senior Member
  • ****
  • Posts: 423
  • Country: us
  • Gender: Male
Re: Selecting an item after running executescript.
« Reply #3 on: Nov 08, 2018, 14:53:00 PM »
I would think that selection sets would be the way to go instead of using pselect.   You have this;

Code: [Select]
===snip===
;; set object and get layer name
(setq e (ssname (ssget) 0))
(setq vlaobj (vlax-ename->vla-object e))
(setq layername (vlax-get-property vlaobj 'layer))
;; end set
(COMMAND "PSELECT" "P" "")
(executescript "X:/Design Aids/scripts/cdback.cod")
(COMMAND "PSELECT" "P" "")
===snip===

But I would do that with something more like this...

Code: [Select]
; get object ename and make selection set
; Limit selection to CADmep objects
(setq ss1 (ssadd (setq e (ssname (ssget '((0 . "MAPS_SOLID"))) 0))))
; get layer name
(setq layername (vlax-get-property (vlax-ename->vla-object e) 'layer))
; execute script on selection set 1
(executescript "X:/Design Aids/scripts/cdback.cod" ss1)
; if you need select and grip the selection set again use...
(sssetfirst nil ss1)

Offline Darren Young

  • Premier Member
  • *****
  • Posts: 2081
  • Country: us
  • Gender: Male
    • BIM There Done That.
Re: Selecting an item after running executescript.
« Reply #4 on: Nov 08, 2018, 21:15:28 PM »
"Select P" for Previous I get. Just didn't know what "PSELECT" was as that's not a command.

So, get your selection set.

Look through each item in your selection set.
As you're looking through each item in your selection set. extract the entity name of that item and select that.

Any select objects prompt allows passing an entity name, not just a selection set.

I typically build a look that repeats for the number of items in my selection set. I then look at the first item in the selection set and get it's entity name. My loop can now do anything it wants.

And because I'm lazy, I don't increment a counter....I just then remove that entity from the fist selection set so the second item then becomes the first.