Trying to delete splines out of a block based on the number of control points...

Trying to delete splines out of a block based on the number of control points...

Anonymous
Not applicable
1,970 Views
7 Replies
Message 1 of 8

Trying to delete splines out of a block based on the number of control points...

Anonymous
Not applicable

I need help getting over the finish line with this one...I had it working a while ago then **something** happened and I can't get it back.

 

I am writing several LISPS that will delete splines out of a block based on how many control points there are in each spline.  I'm currently stuck, every time I run the attached routine in the attached file, it halts with the block editor open.

 

There must be some syntax problem going on that I can't recognize.  

 

If someone could fix the attached LISP I'd greatly appreciate it!  I'd like to keep using the COND command and not use IF's, as this will be part of a much larger routine later on.  Thanks in advance for any help!

0 Likes
Accepted solutions (1)
1,971 Views
7 Replies
Replies (7)
Message 2 of 8

Kent1Cooper
Consultant
Consultant

AutoLisp function names come first  after the opening left parenthesis, followed by  the appropriate arguments.  Try changing this part:

 

      (((vla-get-NumberOfControlPoints b) > 5)
       ;;the object has MORE than 5 control points
       (vla-delete b)
       ;; delete it
      )

 

to this:

 

      ((> (vla-get-NumberOfControlPoints b) 5)
       ;;the object has MORE than 5 control points
       (vla-delete b)
       ;; delete it
      )

 

ALSO, I think you're missing a closing right parenthesis here:

 

      (T ()
       )

       )
     )
   ;;progn
 )
 ;;if

 

which should be:

 

      (T ())
       ); cond

       ); repeat
     )
   ;;progn
 )
 ;;if

 

And since that (repeat) is a single  function, it can be the 'then' expression for the (if) function, by itself, without  wrapping a (progn) function around it.

 

May I assume that the fall-back (T ()) condition will actually have something to be done, if no previous conditional test is satisfied?  If not, you can omit that line entirely.

 

Kent Cooper, AIA
Message 3 of 8

Anonymous
Not applicable

Thanks very much for your help! 

 

I also did discover that i couldn't use a wildcard such as "*line" earlier in the ssget statement....  It won't grab a spline that way, I will have to add some extra code to deal with just the splines.  GRRRR...

 

..but again, thanks for your other info, I will definitely add that to my bank of knowledge!

0 Likes
Message 4 of 8

cadffm
Consultant
Consultant


a b c d e f addprop vnum
missing local variables?


(setq c nil)
???


Why you are using this: (setq a (ssget "_x" '((0 . "*line"))))
A LINE have only TWO (start&end) POINTS.

If you want this tool only for SPlines, you should filter only splines (setq a (ssget "_x" '((0 . "SPLINE"))))

And this: ((vla-get-NumberOfControlPoints b) > 5) => (80 > 5) => 80 is not a function.. error >> (> (vla-get-NumberOfControlPoints b) 5)

And vla-get-NumberOfControlPoints crashes on *POLYLINEs


"(T ())" ???
A cond-structure with only one test, you can also use IF (if (> (vla-get-NumberOfControlPoints b) 5) (vla-delete b))

 

But what is if the Layer of Spline is LOCKED? You have to handle locked Layer situation..


(vl-cmdf "_.bclose" "_sav")
If you change nothing AutoCAD dont ask for saving changes.. and you fire "_sav" to the commandline. Isn't well. better (vl-cmdf "_.bsave" "_.bclose")


And then there is (not) a missing bracket in the code - the closing IF-bracket of (if (setq a (ssget

-

But you dont need to use the BlockEditor:

(defun c:vnum1818
       (/ bks i bkl bk removedup)
  (vl-load-com)
  ;;********************************************************************************************;;
  ;;****************************************  UTILITIES ****************************************;;
  ;;********************************************************************************************;;
 
  (defun removedup (l)
    (if    l
      (cons (car l) (removedup (vl-remove (car l) (cdr l))))
      ;;removing duplicate element from the list
    )
  )
  ;;********************************************************************************************;;
  ;;**************************************  MAIN PROGRAM ***************************************;;
  ;;********************************************************************************************;;
  (if (setq bks (ssget '((0 . "insert"))))
    ;;select block on screen
    (progn
      (vla-startundomark
    (vla-get-activedocument (vlax-get-acad-object))
      )
      (repeat (setq i (sslength bks))
    ;;setting the repeat count
    (setq bkl
           (cons (cdr (assoc 2 (entget (ssname bks (setq i (1- i)))))) ; google for effectivename if the performance is slow / dynamic anonym blocks..
             bkl
           )
    )
    ;;getting the selected block list
      )
      (setq bkl (removedup bkl))
;#######################################
      ;;removing duplicate names of block
      (foreach bk bkl
    ;;running code for every block
    (vlax-for item (vla-item (vla-get-Blocks(vla-get-activeDocument(vlax-get-Acad-Object))) bk)
      (if (and
        (= (vla-get-ObjectName item) "AcDbSpline")
        (> (vla-get-NumberOfControlPoints item) 5)
              )
              (vla-delete item) ; ATTENTION: But what is if the Layer of Spline is LOCKED? You have to handle locked Layer situation..
      )
    )
      ) ;; foreach
;#######################################
      (command "_.REGENALL")
      ;;restoring the variables again
      (vla-endundomark
    (vla-get-activedocument (vlax-get-acad-object))
      )
      ;;ending the undo mark
    )
    ;; progn
  )
  ;; if
  (princ)
)

 

 

 

Sebastian

0 Likes
Message 5 of 8

Anonymous
Not applicable

Thanks for your contribution:

 

I am using other LISP routines that I paid someone to write for me, and then taking them apart/re-configuring for other uses.  Unfortunately I occasionally stumble, as I am still learning.  I thought that the "*line" would act as a wildcard and also grab splines.

 

I was also just a second ago reading about locked condition, but I know for a fact that that will NEVER happen in the context I am working in.

0 Likes
Message 6 of 8

cadffm
Consultant
Consultant
"*line" would act as a wildcard and also grab splines.

"SPLINE" is matching to "*LINE", the probkem is ALSO for your following code.

Sebastian

0 Likes
Message 7 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

@cadffm wrote:

....
And vla-get-NumberOfControlPoints crashes on *POLYLINEs

"(T ())" ???
A cond-structure with only one test, you can also use IF (if (> (vla-get-NumberOfControlPoints b) 5) (vla-delete b))

....


I thought of that, too, but didn't say anything in my first Reply.  The first condition, about Splines, should be something like this, testing both whether it's a Spline and how many control points it has:

 

    (cond ;;applying conditions here
      ( (and

          (= (vla-get-ObjectName b) "AcDbSpline")

          (> (vla-get-NumberOfControlPoints b) 5)

        ); and
          ;;the SPLINE has MORE than 5 control points
        (vla-delete b)
        ;; delete it

      ); Spline condition

 

or, alternatively, the condition's test being merely whether it is a Spline, and only if it is, checking the number of control points:

 

    (cond ;;applying conditions here
      ((= (vla-get-ObjectName b) "AcDbSpline")

        (if (> (vla-get-NumberOfControlPoints b) 5)

          ;;the SPLINE has MORE than 5 control points
          (vla-delete b)
            ;; delete it

        ); if

      ); Spline condition

 

with at least one added condition, using different test(s), for Polylines.

 

If you want to find Polylines and Splines, but ignore Lines, you can do that in a couple of ways, either checking for both types overtly:

 

(ssget "_x" '((0 . "SPLINE,*POLYLINE")))

 

[which will cover both "heavy" and "lightweight" Polylines], or checking for the entity type to end in "LINE" but have at least two other characters before that so as to prevent selection of LINEs or XLINEs or MLINEs:

 

(ssget "_x" '((0 . "*??LINE")))

Kent Cooper, AIA
Message 8 of 8

Anonymous
Not applicable

my cup runneth over!

0 Likes