Visual LISP, AutoLISP and General Customization

Reply
Contributor
Dj_T_Rex2002
Posts: 15
Registered: ‎08-23-2013
Message 1 of 6 (200 Views)

Help on changing multiple objects

200 Views, 5 Replies
09-05-2013 07:01 AM

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

 

*Expert Elite*
scot-65
Posts: 2,122
Registered: ‎12-11-2003
Message 2 of 6 (172 Views)

Re: Help on changing multiple objects

09-05-2013 04:00 PM in reply to: Dj_T_Rex2002

A quick revision:

 

  (setq num 0 entX nil)
  (if (setq entX (ssget ":smileyfrustrated::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
Dyslexia is a permanent physical disability that cannot be seen.
Contributor
Dj_T_Rex2002
Posts: 15
Registered: ‎08-23-2013
Message 3 of 6 (153 Views)

Re: Help on changing multiple objects

09-06-2013 10:57 AM 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.

Distinguished Contributor
bhull1985
Posts: 417
Registered: ‎07-17-2013
Message 4 of 6 (149 Views)

Re: Help on changing multiple objects

09-06-2013 12:05 PM 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 :smileyhappy:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Distinguished Contributor
bhull1985
Posts: 417
Registered: ‎07-17-2013
Message 5 of 6 (146 Views)

Re: Help on changing multiple objects

09-06-2013 12:07 PM 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!
*Expert Elite*
scot-65
Posts: 2,122
Registered: ‎12-11-2003
Message 6 of 6 (140 Views)

Re: Help on changing multiple objects

09-06-2013 03:31 PM 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
Dyslexia is a permanent physical disability that cannot be seen.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community