subst cons entmod

Discussion in 'AutoCAD' started by mnash, Mar 16, 2005.

  1. mnash

    mnash Guest

    I've come up with this

    (setq bscl 2)
    (setq blk (ssget "X" '((0 . "INSERT") (2 . "ICON-##"))))
    (setq scale (entget blk))
    (setq scale (subst (cons 41 bscl)(assoc 8 blk) blk))
    (entmod scale)

    Pretty sure the error is in the fourth line, but I can't see it
    I also wish to change the 42 and 43 values as well
     
    mnash, Mar 16, 2005
    #1
  2. mnash

    Jürg Menzi Guest

    Hi mnash
    Yes, thats true...
    (setq scale (subst (cons 41 bscl)(assoc 41 scale) scale)
    scale (subst (cons 42 bscl)(assoc 42 scale) scale)
    scale (subst (cons 43 bscl)(assoc 43 scale) scale)
    )
    (entmod scale)

    Cheers
     
    Jürg Menzi, Mar 16, 2005
    #2
  3. mnash

    Casey Guest

    It also looks like you are trying to 'entget' a slection set, not an entity.
    This won't work so swell if there is more than one insertion of any
    "ICON-##" block in the drawing. In fact, i don't think it should work at
    all. I'm guessing the error you are getting is:

    ; error: bad argument type: lentityp <Selection set: ###>

    You need to select the entity from the selection set and modify that.

    Casey
     
    Casey, Mar 16, 2005
    #3
  4. mnash

    Tom Smith Guest

    A couple of things. Your ssget will return a selection set of unknown length, or nil, not an enitity name. You need to do the entmod on all members of the set. Or if you're reasonably sure that there's on;y one of these blocks, maybe you could just operate on the first member of the set.

    I find it a lot easier to keep track of these things if I give the variables names that convey what kind of thing they are -- sset, ename, edata, etc.

    Also, you need some bulletproofing. You have to be sure a block was found before you entget it or entmod it. Something like this (untested):

    (setq b-scl 2)
    (or
    (and
    (setq b-sset (ssget "X" '((0 . "INSERT") (2 . "ICON-##"))))
    (setq b-ename (ssname b-sset 0))
    (setq b-edata (entget b-ename))
    (entmod (subst (cons 41 b-scl)(assoc 8 b-edata) b-data))
    )
    (*error* "Problem finding block")
    )

    The "and" will abort if any of the statements within it fail, and the "or" will terminate your program if this happens. Other ways of doing this are possible, of course. The main thing is to abort if the block isn't found.
     
    Tom Smith, Mar 16, 2005
    #4
  5. mnash

    mnash Guest

    I thought that was what I was doing in the second and third lind...no?
     
    mnash, Mar 16, 2005
    #5
  6. mnash

    mnash Guest

    Here's what I'm trying to do....
    Look for a block that has "ICON-" in the name. The block could be called "ICON-01", "ICON-02", "ICON-03" and so on.
    If there is no icon, then continue on with the command.
    If there is an icon, I want to change the values of 41, 42, 43 to a number.
    The number being the scale of the block that is a previously defined variable "b_scl" in my lisp, and then continue with the rest of the program. In most cases, there will only be one ICON, but if there are two, that's okay too.
     
    mnash, Mar 16, 2005
    #6
  7. mnash

    BillZ Guest

    You were close...

    Untested:

    (setq bscl 2)
    (setq blk (ssget "X" '((0 . "INSERT") (2 . "ICON-##"))))
    (if blk
    (progn
    (setq cnt 0)
    (repeat (sslength blk)
    (setq entityname (ssname blk cnt)
    entitylist (entget entityname)
    cnt (1+ cnt)
    NewScaledEntity (subst (cons 41 bscl)(assoc 41 entitylist) entitylist)
    )
    (entmod entitylist)
    ) ;repeat
    );progn
    );if

    Bill
     
    BillZ, Mar 16, 2005
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.