Subtract Lisp Help

Discussion in 'AutoCAD' started by jojo, May 13, 2004.

  1. jojo

    jojo Guest

    Ok, I am trying to create a lisp that will subtract an object from multiple objects without creating one large object out of all of the original objects. Below is what I have. This is my first time trying to access vlax stuff, so that is probably where the problem is, and I dont know what this means, but I get a lot of jumbled text that appears at the command prompt when this script runs...

    Also, this is setup to just subtract one entity, and it would be nice if it could be setup to subtract multiple entities, but any help would be great! Thanks!!!

    (defun c:sub()
    (setq xx 0 rr 0 objs1 nil objs2 nil objstempx nil objstemp nil obj nil objx nil)
    (princ "Select 3D objects to subtract from : ")
    (setq objs1 (ssget))
    (princ "select one object to subtract")
    (setq objs2 (ssget))
    (setq xx (sslength objs1))
    (repeat xx
    (vl-load-com)
    (setq subobj (entlast))
    (command "copy" subobj "" "0,0" "0,0" "")
    (setq subobjx (entlast))
    (setq objx (entget (ssname objs1 rr)))
    (setq obj (vlax-ename->vla-object objx))
    (command "subtract" obj "" subobjx "")
    (setq rr (+ 1 rr))
    )
    )
     
    jojo, May 13, 2004
    #1
  2. jojo

    Mark Propst Guest

    you don't need the vlax stuff when you're using the command syntax anyway so
    that's not your problem here.

    here's a really tacky little workaround, since you're okay with the command
    usage and I don't know off hand if there are vla funcs to do solid editing
    but this should show you one way to approach it.
    The masters here will blow this away with much better ways but this is what
    I could come up with off the top of my head

    (defun C:SubtractMulti( / solidset soltoSub Solent1 Solent2 i)
    (command "._Undo" "End")
    (command "._Undo" "Begin")
    (princ "\nSelect 3D objects to subtract from : ");<---probably want a
    newline
    ;might as well filter for solids since that's what you want
    (and
    (setq solidset (ssget'((0 . "3DSOLID"))))
    (princ "\nSelect one object to subtract")
    (setq solToSub(ssget "+.:E:S" '((0 . "3DSOLID"))))
    (if solToSub(setq solToSub(ssname solToSub 0)));convert set to ename
    (setq i 0)
    (repeat(sslength solidset)
    (command"Copy" soltosub "" '(0 0) '(0 0)"")
    (setq solent2(entlast))
    (setq solent1(ssname solidset i))
    (command "subtract" solent1 "" solent2 "")
    (setq i(1+ i))
    )
    (entdel solToSub )
    );and

    (command "._Undo" "End")
    (princ)
    )

    I only tested with very small example so there may be much wrong with it but
    it seemed to work on small group of solids.
    good luck


    multiple objects without creating one large object out of all of the
    original objects. Below is what I have. This is my first time trying to
    access vlax stuff,

    (you weren't really accessing any vlax anything)

    so that is probably where the problem is, and I dont know what this means,
    but I get a lot of jumbled text that appears at the command prompt when this
    script runs...

    that is what you get when you look at the entitylist of a solid with (entget
    solident)
    it could be setup to subtract multiple entities,

    at first I thought you only wanted to subtract one thing,
    didn't have time to get a multiple set to work, maybe you can figure that
    out
    hth
    Mark
     
    Mark Propst, May 13, 2004
    #2
  3. jojo

    Jamie Duncan Guest

    Hey JoJo

    Did you see the lisp I posted for the layers thing?

    A few words of advice:

    (defun c:sub()

    by doing this. all variables within the routine are global. I assume this
    is for testing purposes - and the reason for point #2

    (setq xx 0 rr 0 objs1 nil objs2 nil objstempx nil objstemp nil obj nil objx
    nil)

    you don't need this if they are local variables.

    and for readability

    (setq xx 0
    rr 0
    etc
    objx nil
    )

    is much easier to read and to debug.

    (command "subtract" obj "" subobjx "")

    is for solids or regions - you should test or filter the selection set to
    make sure that the user has selected a solid or region

    (ssget '((0 . "3dsolid"))) for example

    this

    (setq xx (sslength objs1))
    (repeat xx

    can be made into this:

    (repeat (sslength objs1)

    and this

    (vl-load-com)

    need only be done once per session

    And the objects you are speaking of are obviously solids and so the routine
    may be simplified - if you use layers to your advantage,

    ie. copy the base objects and the subtraction objects and put them on a
    separate layer,, then do the extraction, this way you will end up with the
    base and subtraction objects remaining, and a new compound object on it's
    own unique layer. Thus no underlying geometry is lost and you have
    visibility control.


    Jamie Duncan

    Not one of the 10, but I believe a 'we try harder' medal is
    warranted.....<g>


    multiple objects without creating one large object out of all of the
    original objects. Below is what I have. This is my first time trying to
    access vlax stuff, so that is probably where the problem is, and I dont know
    what this means, but I get a lot of jumbled text that appears at the command
    prompt when this script runs...
    it could be setup to subtract multiple entities, but any help would be
    great! Thanks!!!
     
    Jamie Duncan, May 13, 2004
    #3
  4. jojo

    Jamie Duncan Guest

    Hey Mark,

    I may be out to lunch but from what I've learned the acis model data is
    still copyrighted and acad doesn't have the right to publish it, and thus
    solids are only accessible through the command inyourface.

    so that means the appellation of tacky, albeit accurate, is elevated to
    essential in this instance.


    Jamie Duncan
     
    Jamie Duncan, May 13, 2004
    #4
  5. jojo

    jojo Guest

    Thanks that worked perfectly!

    I dont really need to make it subtract multiple objects from the first selection set, I can just union all those objects before i do the routine! So Thanks!
     
    jojo, May 13, 2004
    #5
  6. jojo

    jojo Guest

    thanks jamie! I havent tried your script from the layers post yet, The other guy helped me finish on...I will try it thought cuz the one we created was a little slow when used on 60,000 objects :) LOL

    but thanks for all the input...
     
    jojo, May 13, 2004
    #6
  7. jojo

    Jeff Mishler Guest

    "Mark Propst" <notmark-at-atreng-dot-com> wrote in message
    <snip>

    Just so you know, yes there is. This isn't an answer in any way to the
    original question as I don't have the time right now to look at it, but here
    is a demonstration of how to implement subtraction via ActiveX.

    This routine requires a 3Dsolid object and a circle or closed pline to act
    as a hole punch to already exist in a drawing.

    HTH for future thoughts,
    Jeff

    (defun c:holepunch (/ ss_solid solid ss_punch punch space solid1
    solid2 new_region doc
    )
    (if (and
    (princ "\nSelect Solid you wish to punch: ")
    (setq ss_solid (ssget ":S" '((0 . "3DSOLID"))))
    (setq solid (vlax-ename->vla-object (ssname ss_solid 0)))
    (princ "\nSelect Circle or Closed Polyline to punch with: ")
    (setq ss_punch (ssget ":S" '((0 . "CIRCLE,LWPOLYLINE"))))
    (setq punch (vlax-ename->vla-object (ssname ss_punch 0)))
    (if (vlax-property-available-p punch 'closed)
    (= (vla-get-closed punch) :vlax-true)
    t
    )
    (setq doc (vla-get-activedocument (vlax-get-acad-object)))
    )
    (progn
    (setq space (if (= 1 (vla-get-activespace doc))
    (vla-get-modelspace doc) ;we're in modelspace
    (if (= (vla-get-mspace doc) :vlax-true)
    (vla-get-modelspace doc) ;we're in modelspace
    ;thru paperspace VPort
    (vla-get-paperspace doc) ;we're in paperspace
    )
    )
    )
    (vla-startundomark doc)
    (setq new_region (vlax-invoke-method
    space
    'addregion
    (vlax-safearray-fill
    (vlax-make-safearray
    vlax-vbobject
    (cons 0 0)
    )
    (list punch)
    )
    )
    new_region (car (vlax-safearray->list
    (vlax-variant-value new_region)
    )
    )
    solid1 (vlax-invoke-method
    space 'addextrudedsolid new_region 100000.0 0)
    solid2 (vlax-invoke-method
    space 'addextrudedsolid new_region -100000.0 0)
    )
    (vlax-invoke-method solid1 'boolean acunion solid2)
    (vlax-invoke-method solid 'boolean acsubtraction solid1)
    (vla-delete new_region)
    (vla-endundomark doc)
    )
    (princ "\nInvalid object(s) selected, try again...")
    )
    (princ)
    ) ;defun
     
    Jeff Mishler, May 13, 2004
    #7
  8. jojo

    Mark Propst Guest

    Awesome dude!
    Thanks!
    :)
    Mark

     
    Mark Propst, May 13, 2004
    #8
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.