Author Topic: Polylines and the Invalid Class Error  (Read 2371 times)

0 Members and 1 Guest are viewing this topic.

rynoski

  • Guest
Polylines and the Invalid Class Error
« on: April 09, 2015, 02:27:17 PM »
Hi folks. Been looking about for an answer this riddle all over and every time I think I have it licked it breaks again.
Background - So I have a drawing with ohhhh 35,000 polylines. Mixed variety. I thought there were some old ones but so far all object names are either "AcDbPolyline", or "AcDb2dPolyline". Unless I missed my guess these are both post R14 polyline types. Many open and many closed. I am developing a program that updates these polylines. In a nutshell the closed donut plines are locations of importance (I cannot say what they are) - and the open polylines are supposed to connect to the centers. Sometimes they dont. That's where I come in.

I tried to use the Pedit command but found out real fast once you do and try to join it it gives the Invalid Class error. I searched and all and started seeing the vla-release-object commands that I thought started to do the trick but I still get the errors even after I place that code after a vla-object grab. As I iterate through surrounding objects its usually ok on the first vlisp action. Its when I get to the second time it needs to be modified again (other endpoint) that even after a release it still generates the class error.

My ssget filter is grabbing all open lw or older polylines with 70.128 or 70.0 flags. Now this thing runs in a different region that has the same mixture of lw and older polylines and runs perfectly over and over and over. I run it in a  different section and poof no worky. I have to be missing something. I thought at first it was the 128 vs 0 flag but so far the only thing i know for sure is once ia pline has been acted upon then it becomes the invalid class (t)error suspect. lol. I am going to post some code to illustrate whats going on. I know there are ways to improve the code but I like to line by line sometimes because it helps me understand what I do without going into comment hell. I want to try to focus on why i get the error and how to fix it not my poorly written code  ;) --  Many thanks in advance for help or suggestions. My vars and counters were working properly but in relabeling for this post i may have missed something. I will add comments to sections if someone needs to see intent.

Code - Auto/Visual Lisp: [Select]
  1.     (while (< ifixcnt (length plines))
  2.       (setq fixit nil vptlist nil)
  3.       (setq fixpline (nth ifixcnt plines))
  4.       (if (not (not vlapline))(vlax-release-object vlapline))
  5.       (setq vlapline (vlax-ename->vla-object fixpline))
  6.       (setq templist (vlax-get (vlax-ename->vla-object fixpline) 'Coordinates))
  7.       (cond
  8.         ((member 0.0 templist)(vertlisterldr templist))
  9.         ((not (member 0.0 templist))(vertlister templist))
  10.       )  ;formats the coord list how i want it for other code areas
  11.       (cond
  12.         ((member 0.0 templist)(setq elevflag T))
  13.         ((not (member 0.0 templist))(setq elevflag nil))
  14.       )  ;fix for vlax issue of elevation in coords, elevation should all be 0 or reset to 0
  15.       (setq endp1 (car vertlist))
  16.       (setq endp2 (last vertlist))
  17.       (setq e1dist (distance center endp1))
  18.       (setq e2dist (distance center endp2))
  19.       ;center is the center of the donut obtained earlier
  20.       (cond
  21.         ((> e2dist e1dist)(setq goodend endp1))
  22.         ((> e1dist e2dist)(setq goodend endp2))
  23.       )
  24.       (setq gap (distance goodend center))
  25.       (cond
  26.         ((> gap 700)(setq fixit T))
  27.         ((<= gap 700)(setq fixit nil))
  28.       )
  29.       (if (= fixit T)
  30.         (progn
  31.           (vl-cmdf "line" center goodend "")
  32.           (setq lasty (entlast))
  33.           (if (not (not vlapline))(vlax-release-object vlapline))
  34.           (vl-cmdf "pedit" fixpline "J" lasty "" "W" "1200" "")  
  35.           (setq vlapline (vlax-ename->vla-object fixpline))
  36.           (vla-put-ConstantWidth vlapline 1200.0)
  37.           (vla-put-Color vlapline 3)
  38.           (vla-put-Elevation vlapline 0.0)
  39.           (vla-Regen *active-document* acAllViewports)
  40.         )
  41.         (if (/= gap 0.0)
  42.           (progn
  43.             (setq chgvert vertlist)
  44.             (cond
  45.               ((= goodend endp1)(setq chgvert (subst center (car vertlist) vertlist)))
  46.               ((= goodend endp2)(setq chgvert (subst center (last vertlist) vertlist)))
  47.             )
  48.             (foreach item chgvert
  49.               (setq cordx (list (car item)))
  50.               (setq cordy (list (last item)))
  51.               (cond
  52.                 ((= elevflag nil)(setq vptlist (append vptlist cordx cordy)))
  53.                 ((= elevflag T)(setq vptlist (append vptlist cordx cordy '(0.0))))
  54.               )
  55.             )
  56.             (setq safenum (1- (length vptlist)))
  57.             (setq safedot (cons 0 safenum))
  58.             (if (not (not vlapline))(vlax-release-object vlapline))
  59.             (setq vlapline (vlax-ename->vla-object fixpline))
  60.             (setq coordarray (vlax-make-safearray vlax-vbDouble safedot))
  61.             (vlax-safearray-fill coordarray vptlist)
  62.             (vla-put-coordinates vlapline coordarray)
  63.             (vla-Regen *active-document* acAllViewports)
  64.           )
  65.           (Princ "Line is already correct \n")
  66.         )
  67.       )    
  68.       (setq ifixcnt (1+ ifixcnt))
  69.     );inner while
  70.  

In a nutshell:
I have a list of donuts and the plines that go into those donuts.
For every donut and its subsequent plines
Take the plines one by one, and find the correct end
After finding the correct end measure the distance to the donut center
if gap is too big
then make the pline go from the end to the center
else if the gap is not 0
then skooch it over to the center (chg end point to the donut center)
else its ok

the elevation thing surprised me a few points in time and i band-aided it every time.
The elevation is useless and needs to be 0 or set to 0 each time. There is a sub routine vertlister that reformats the coordinates to something i like better for other areas of the program. I unravel it in the foreach statement and tack on an elevation if that's how it came right before i modify the object. I am willing to try most things. I could separate the polylines thereby ruling out whether its the LW or the older plines causing mischief but again its running in another area with mixed lines perfectly....  Closing and re-saving drawing after each edit is out of the question. I sort via enam (which i recently discover does actually change just not while in session).  So re-drawing the polylines is a LAST RESORT. I can post some object dumps if need be. Again thanks in advance peeps.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Polylines and the Invalid Class Error
« Reply #1 on: April 09, 2015, 02:51:50 PM »
Post a sample drawing ... BTW welcome to TheSwamp  :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

rynoski

  • Guest
Re: Polylines and the Invalid Class Error
« Reply #2 on: April 09, 2015, 06:31:17 PM »
Post a sample drawing ... BTW welcome to TheSwamp  :)

Why thank you RJ! I decided to post here because other than Lee-Mac, & Afra-Lisp this forum and Cad tutor usually have the most active helpers and I've found more answers in these places than any.  :)

I can't post the real drawing due to legal crap (NDA) and national security concerns (its not nearly as important as that sounds but if in the wrong hands...) so I simply cannot post the entire drawing.  I can see about cutting out a small portion and taking out sensitive information for the purpose of demonstration.

Thanks

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Polylines and the Invalid Class Error
« Reply #3 on: April 09, 2015, 06:54:37 PM »
I decided to post here because other than Lee-Mac, & Afra-Lisp this forum and Cad tutor usually have the most active helpers and I've found more answers in these places than any.  :)

Many thanks for the mention! - I'll try to help as best I can with your issue if I get some time.

Welcome to the Swamp - you'll like it here  :-)

rynoski

  • Guest
Re: Polylines and the Invalid Class Error
« Reply #4 on: April 09, 2015, 09:19:23 PM »
I decided to post here because other than Lee-Mac, & Afra-Lisp this forum and Cad tutor usually have the most active helpers and I've found more answers in these places than any.  :)

Many thanks for the mention! - I'll try to help as best I can with your issue if I get some time.

Welcome to the Swamp - you'll like it here  :-)

My pleasure. You have some impressive programs to say the very least. One of the early bugs of the program was the ssget crossing sets were incomplete because I wasn't zoomed out. That part of your site was highly useful! So much so that I am planning on making a donation to your site soon as I get a job again. I just moonlight as a programmer.  :)

rynoski

  • Guest
Re: Polylines and the Invalid Class Error
« Reply #5 on: April 10, 2015, 01:08:26 AM »
 :wideeyed:I've been debugging this thing all night and its finally working with a host of (GC) and (entupdt [var]) calls immediately after any mod operation. It runs slower now but it runs.

Thats the weird thing here. I would occasionally get it to work IF i stepped through each call to getting a vla object by iteration. I set up break points right before those calls and the thing would work. Close and reopen the drawing try it again on full speed no breaks - crash.

Its almost as if it was going too fast that the thing couldnt update itself before it got to the next call....

Then to test another theory I commented all the entupd calls and it turns out it works with only the garbage collection calls. Weird. A little PO'd that it runs like a castrated steer now but I am at least grateful that it works...

rynoski

  • Guest
Re: Polylines and the Invalid Class Error
« Reply #6 on: April 10, 2015, 01:43:39 AM »
And this is what fixed it. I always wondered if my Garbage Collection calls were actually doing anything. As it turns out -  it actually does do something  ;)

My hunch came from surprise surprise the ACAD Vlisp Help menu. I was looking thru the command functions because I couldnt remember if there was a vlisp equivalent to Regen and then it suddenly dawned on me that it was already in the code. But while it was there poking around the commands by Letter, I noticed a VBA-release command that was different than the one I read to use. "vlax-object-released-p". while I was there reading what difference it had between the other used in my original code, it starts out to say this:

Quote
... A VLA-object is not released until you invoke vlax-release-object on the object, or normal AutoLISP garbage collection occurs or ...
.

Apparently the GC call does something the release does not. Either that or I wasnt coding it in the right spot. :)


Code - Auto/Visual Lisp: [Select]
  1.  
  2. (while (< fixcount (length plinesubls))
  3.     (vla-Regen *active-document* acAllViewports)
  4.     (setq center (car (nth fixcount allcenters)))
  5.     (setq data (nth fixcount plinesubls))
  6.     (setq donut (car data))
  7.     (setq plines (cadr data))
  8.     (setq vlaplines nil)
  9.     --->>  (gc)   <<--------
  10.     (setq ifixcnt 0)
  11.  
  12.     ;[--- posted code below---]
  13.  
  14.     (while (< ifixcnt (length feeds))
  15.       (setq fixit nil vptlist nil)
  16.       (setq fixfeed (nth ifixcnt feeds))
  17. ....
  18. ....
  19.  

What a crazy night

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Polylines and the Invalid Class Error
« Reply #7 on: April 10, 2015, 09:53:16 AM »
Glad you got it sorted .. if you post a sample maybe we can get the program running a little better than a 'castrated steer' :).

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC