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

Help on changing multiple objects

5 REPLIES 5
Reply
Message 1 of 6
Dj_T_Rex2002
392 Views, 5 Replies

Help on changing multiple objects

I am trying to select multiple objects and change them. However, the following code lets me only change one at a time. Even when I select a window around obejcts, it only changes a single item. Please help, thanks.

 

start of Same_Cannoscale.lsp


(defun C:SCS ( / anno-v ent dict cansc entsc sc-list test oce)
 (setq anno-v (getvar "ANNOALLVISIBLE"))
 (setvar "ANNOALLVISIBLE" 1)
 (if (= (getvar "CVPORT") 1)
  (princ "\nIn Paperspace. ")
  (if (setq ent (ssget ":S:L"))
   (if
    (and
     (setq dict (cdr (assoc 360 (entget (setq ent (ssname ent 0))))))
     (setq dict (dictsearch dict "AcDbContextDataManager"))
     (setq dict (dictsearch (cdr (assoc -1 dict)) "ACDB_ANNOTATIONSCALES"))
    )
    (progn
      (setq cansc (getvar "CANNOSCALE") oce (getvar "CMDECHO"))
      (foreach n dict
        (if (and
              (= (car n) 350)
              (setq entsc
                   (cdr (assoc 300 (entget (cdr (assoc 340 (entget (cdr n)))))))
              )
            )
            (if (= entsc cansc)
                (setq test T)
                (setq sc-list (cons entsc sc-list))
            )
        )
      )
      (setvar "CMDECHO" 0)
      (if (not test)
          (command "-objectscale" ent "" "_a" cansc "")
      )
      (if sc-list 
          (progn
             (command "-objectscale" ent "" "_d")
             (foreach n sc-list (command n))
             (command "")
          )
      )
      (setvar "CMDECHO" oce)
    )
    (princ "\nObject selected is not annotative. ") 
   )
  )
 )
 (setvar "ANNOALLVISIBLE" anno-v)
(command "_.regenall"))
(princ)
)

 

5 REPLIES 5
Message 2 of 6
scot-65
in reply to: Dj_T_Rex2002

A quick revision:

 

  (setq num 0 entX nil)
  (if (setq entX (ssget ":S:L"))

   (while (< num (sslength entX))
    (if
     (and

      (setq dict (cdr (assoc 360 (entget (setq ent (ssname entX num))))))
      (setq dict (dictsearch dict "AcDbContextDataManager"))
      (setq dict (dictsearch (cdr (assoc -1 dict)) "ACDB_ANNOTATIONSCALES"))
     );and

     [the rest of if...]

    );if

   (setq num (1+ num))

  );while

 

Original program shows "ent" to be both a selection set, then a single entity.

We need to pull these apart as separate objects. I named the selection set "entX" as an example.

Next is to wrap a while around the nested if.

Finally add a counter that doubles as a flag to escape the while loop.

 

entX and num to be declared in the defun line (after the forward slash).

 

untested.

Hope this helps.

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 3 of 6
Dj_T_Rex2002
in reply to: Dj_T_Rex2002

Ok, so I changed what you told me to change. However, I think I lost track of what you are trying to say lol. This is what I did. I quite did not understand what you meant by  pulling both ents apart.

start of Same_Cannoscale.lsp


(defun C:SCS ( / anno-v entX dict cansc entXsc sc-list test oce)
 (setq anno-v (getvar "ANNOALLVISIBLE"))
 (setvar "ANNOALLVISIBLE" 1)
 (if (= (getvar "CVPORT") 1)
  (princ "\nIn Paperspace. ")
  (setq num 0 entXX nil)
  (if (setq entX (ssget ":S:L"))
  (while (<num (sslength entXX)) 
  (if
    (and
     (setq dict (cdr (assoc 360 (entXget (setq entX (ssname entXX num))))))
     (setq dict (dictsearch dict "AcDbContextDataManager"))
     (setq dict (dictsearch (cdr (assoc -1 dict)) "ACDB_ANNOTATIONSCALES"))
    );and
    (progn
      (setq cansc (getvar "CANNOSCALE") oce (getvar "CMDECHO"))
      (foreach n dict
        (if (and
              (= (car n) 350)
              (setq entXsc
                   (cdr (assoc 300 (entXget (cdr (assoc 340 (entXget (cdr n)))))))
              )
            )
            (if (= entXsc cansc)
                (setq test T)
                (setq sc-list (cons entXsc sc-list))
            )
        )
      )
      (setvar "CMDECHO" 0)
      (if (not test)
          (command "-objectscale" entX "" "_a" cansc "")
      )
      (if sc-list 
          (progn
             (command "-objectscale" entX "" "_d")
             (foreach n sc-list (command n))
             (command "")
          )
      )
      (setvar "CMDECHO" oce)
    );if
    (setq num (1+ num))
    (princ "\nObject selected is not annotative. ") 
   )
  )
 )
 (setvar "ANNOALLVISIBLE" anno-v)
(command "_.regenall"))
(princ)
)

 Funny thing is that it still changes the object to current scale with the changes you told me to do.

Message 4 of 6
bhull1985
in reply to: Dj_T_Rex2002

he means that you were only getting one object changed because instead of a whole selection set the changes were being applied to one entity, instead.

Pulling apart i believe was analogous for separating correctly, and using the while function and a counter to include each single entity into one selection set....if i followed that correctly myself 🙂

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 5 of 6
bhull1985
in reply to: bhull1985

The "counter"   (setq num (1+ num))

needs to be within the while loop, because it's what is used to get out of the while loop. study up on loop functions if you'd want to learn what all this means

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 6 of 6
scot-65
in reply to: Dj_T_Rex2002

The original program used the variable "ent" first as a selection set (a list of entities), then it was redefined (using setq) to be a single entity [the first entity in the list].
For LISP programming this is acceptable to switch variable types while using the same declared variable, but in other languages this is not acceptable without first destroying the variable.
Thinking about the original program structure, my guess is the code was first written using entsel, then switched to ssget - just to make sure an object was selected.

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


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

Post to forums  

Autodesk Design & Make Report

”Boost