Author Topic: Updating Hatch boundary  (Read 2938 times)

0 Members and 1 Guest are viewing this topic.

serZ

  • Guest
Updating Hatch boundary
« on: May 06, 2017, 04:49:54 PM »
Greetings everyone.

I have stumbled upon a nut that I can't crack no matter what I try and where I look.

A part of a LISP that I'm working on creates a hatch for a given region (created form a polyline) then puts this region through a series of boolean operations (subtraction and intersection)  and then deletes the region because it is no longer necessary.
Here is that part of the code

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ()
  2.  
  3.  
  4.   (setq poly1 (list (vlax-ename->vla-object (car (entsel)))))                             ;pick first polyline                
  5.   (setq poly2  (list (vlax-ename->vla-object (car (entsel)))))                            ;pick second polyline        
  6.   (setq reg1(vlax-invoke mspace 'addregion poly1))                                        ;create first region
  7.   (setq reg2 (vlax-invoke mspace 'addregion poly2))                                       ;create second  region
  8.  
  9.   (setq hatch (vla-addhatch mspace acHatchPatternTypePreDefined "SOLID" :vlax-true ))        ;create hatch object
  10.   (setq col (vlax-create-object "AutoCAD.AcCmColor.16"))                                
  11.   (vla-setRGB col 100 50 12)
  12.   (vla-put-trueColor hatch col)
  13.  
  14.   (vlax-invoke hatch 'appendouterloop  reg1)               ;append reg1 as a hatch boundary
  15.  
  16.   (vla-boolean (car reg1) acIntersection  (car reg2))       ;create intersection between two regions
  17.    
  18.   (vla-delete  reg1)                                                          ;delete  the region
  19.  
  20.   (princ)  
  21.  
  22.   ) ;end fun
  23.  
  24.  


The code works perfectly fine if I don't delete the region or if I delete it (manually or vith vl-delete) after the routine is finished.
I tied to put these commands one by one in the VL editor and see what's going on on the screen.
Apparently the hatch only gets boolean update after I exit the editor and return to my active document.     
I have tried all the update techniques I know: I tried updating both the hatch and the region with vla-update and entmod, regenerating active document with vla-regen, redrawing with redraw. Nothing seems to work.
It seems that there is some other kind of "refresh" going on after you switch from VL editor window to AutoCAD window.

Any ideas will be highly appreciated!
Thank you in advance.

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Updating Hatch boundary
« Reply #1 on: May 06, 2017, 06:11:46 PM »
Try:
Code - Auto/Visual Lisp: [Select]
  1. (vla-evaluate hatch)

serZ

  • Guest
Re: Updating Hatch boundary
« Reply #2 on: May 06, 2017, 06:56:07 PM »
Thanks Lee Mac.

I tried that one too. Doesn't work ((
It's weird that even when put:
Code - Auto/Visual Lisp: [Select]
it updates everything EXCEPT  the hatch! 

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: Updating Hatch boundary
« Reply #3 on: May 06, 2017, 08:55:27 PM »
try:
Code: [Select]
(defun c:test ()
  (vl-load-com)
  (setq mspace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
  (setq poly1 (list (vlax-ename->vla-object (car (entsel))))) ;pick first polyline               
  (setq poly2 (list (vlax-ename->vla-object (car (entsel))))) ;pick second polyline       
  (setq reg1 (vlax-invoke mspace 'addregion poly1)) ;create first region
  (setq reg2 (vlax-invoke mspace 'addregion poly2)) ;create second  region
  (vla-boolean (car reg1) acIntersection (car reg2)) ;create intersection between two regions
  (setq hatch (vla-addhatch mspace acHatchPatternTypePreDefined "SOLID" :vlax-false)) ;create hatch object
  (setq col (vlax-create-object "AutoCAD.AcCmColor.16"))                                 
  (vla-setRGB col 100 50 12)
  (vla-put-trueColor hatch col)
  (vlax-invoke hatch 'appendouterloop reg1) ;append reg1 as a hatch boundary
  (vla-delete (car reg1)) ;delete  the region
  (princ)
)

serZ

  • Guest
Re: Updating Hatch boundary
« Reply #4 on: May 07, 2017, 08:27:28 AM »
Thanks

That solution works well UNTIL boolean intersection creates two separate regions. If you try to apply that kind of boundary to the hatch it will give error.
On the other hand if you append boundary first  and then manipulate it, hatch will follow like a charm. The only problem is that the hatch update happens only at the end of the routine and I can't find a way to force it within it.
All update/evaluate/regen methods that I used affect everything but the hatch.   

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: Updating Hatch boundary
« Reply #5 on: May 07, 2017, 01:24:13 PM »
Thanks

That solution works well UNTIL boolean intersection creates two separate regions. If you try to apply that kind of boundary to the hatch it will give error.
in this case you may want to explode the region and appendouterloop for every new region

serZ

  • Guest
Re: Updating Hatch boundary
« Reply #6 on: May 07, 2017, 04:48:37 PM »
In fact that's how my script works at the moment. I explode the region, test the product of explosion (lines if its mono region, regions if it is multi region). But then I have to also check the island regions, to see if they intersect or outside or inside the zone of intersection. All in all that makes the code one big mouthful. This method of simply "booleaning" the hatch would be so much easier if it wasn't for this little hiccup.

Oh well, I guess for the time being I will just have to leave all the regions an make an additional lisp to clean up all the debris after the main routine.

Thanks guys!

serZ

  • Guest
Re: Updating Hatch boundary
« Reply #7 on: May 09, 2017, 07:23:01 AM »
Voila!!!

To all who is interested.
Apparantly, the only way to force the hatch update is to regenerate from the command line: (command "REGEN").

Cheers!