Jump to content

Create hatch based on the envelope


jan_ek

Recommended Posts

Hello

I have a block containing polyline "Test*".

What would I like to do?

1. Get the shape of the polyline

2. Divide the shape into 2 parts

3. Create a hatch with an RGB color and individual layer (2 shape) (see picture)

Is it possible?

Hatch.png

Link to comment
Share on other sites

  • Replies 31
  • Created
  • Last Reply

Top Posters In This Topic

  • ronjonp

    9

  • BIGAL

    8

  • jan_ek

    8

  • Grrr

    6

Top Posters In This Topic

Posted Images

Are you just avoiding doing manually ?

 

As an automation pretty easy a lisp using this method, do you know how to do lisp ?

pick pt1

pick pt2

pick pt3

pick pt4

line pt1 pt2

-hatch pt1 pat1

-hatch pt2 pat2

Link to comment
Share on other sites

I want to use autolisp. But I have a problem. I don't know how create point list (calculate point of division and get point list from the block).

Link to comment
Share on other sites

My extra question was aimed at do you want the true area1=area2 if so then probably none of the images are correct or just I want to pick two points with some rules like mid of another line.

 

The lisp code is really take what I have already posted converted to lisp.

 

Please post about extra question it complicates things, if not required a1=a2 then its a few minutes to code.

Link to comment
Share on other sites

Hello

The picture are sketches (please no suggest)

I assumed such a scenario.

Search max left/down corner.

Get length polyline and split to 2 part.

Set the point and create two obiect.

 

Maybe this is bad assumption..

Link to comment
Share on other sites

Give this a try. DEMO.

 

(defun c:foo (/ _addhatch _bnd a ao b d doc e ll mp o s sp ur vc vs)
 (defun _addhatch (e c sp l / h)
   (if	(setq h (vla-addhatch sp achatchpatterntypepredefined "SOLID" :vlax-false))
     (progn (vlax-invoke h 'appendouterloop (list e))
     (vla-put-color h c)
     (vla-evaluate h)
     (vla-update h)
     (entmod (append (entget (vlax-vla-object->ename h)) (list (cons 8 l))))
     h
     )
   )
 )
 (defun _bnd (p l / e)
   (setq e (entlast))
   (command "_.-boundary" p "")
   (cond ((not (equal e (entlast)))
   (entmod (append (entget (setq e (entlast))) (list (cons 8 l))))
   (vlax-ename->vla-object e)
  )
   )
 )
 (if (setq s (ssget '((0 . "LWPOLYLINE") (-4 . "&") (70 . 1))))
   (progn
     (setq doc (vla-get-activedocument (setq ao (vlax-get-acad-object))))
     (vla-startundomark doc)
     (setq sp (vlax-get doc
		 (cond ((= 1 (getvar 'cvport)) 'paperspace)
		       ('modelspace)
		 )
       )
     )
     (vla-put-lock (vlax-ename->vla-object (tblobjname "layer" (getvar 'clayer))) :vlax-false)
     (setq vc (getvar 'viewctr))
     (setq vs (getvar 'viewsize))
     (foreach b (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
(setq o (vlax-ename->vla-object b))
(if
  (and (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list o 'll 'ur))))
       (mapcar 'set '(ll ur) (mapcar 'vlax-safearray->list (list ll ur)))
       (setq e (entmakex (list '(0 . "line") '(8 . "tempfoo") (cons 10 ll) (cons 11 ur))))
  )
   (progn (setq mp (mapcar '(lambda (a b) (/ (+ a b) 2.)) ll ur))
	  (vlax-invoke ao 'zoomcenter mp (setq d (distance ll ur)))
	  (and (setq a (_bnd (list (+ (car mp) (* d 0.1)) (cadr mp)) "BoundaryA"))
	       (_addhatch a 1 sp "HatchA")
	  )
	  (and (setq b (_bnd (list (- (car mp) (* d 0.1)) (cadr mp)) "BoundaryB"))
	       (_addhatch b 3 sp "HatchB")
	  )
   )
)
(and e (entdel e))
     )
     (vla-endundomark doc)
     (vlax-invoke ao 'zoomcenter vc vs)
   )
 )
 (princ)
)

Edited by ronjonp
*Updated code to work in Bricscad
Link to comment
Share on other sites

Cool stuff, Ron!

Few questions though:

Is zooming to the object is necessary?

If it is: maybe with zoomextents and zoomprevious methods would be faster.

 

:geek: Does anyone know if the evaluation of the hatch is important? (vla-Evaluate ..)

Because I used the AddHatch method before without the need of it.

Link to comment
Share on other sites

Cool stuff, Ron!

Few questions though:

Is zooming to the object is necessary?

If it is: maybe with zoomextents and zoomprevious methods would be faster.

 

:geek: Does anyone know if the evaluation of the hatch is important? (vla-Evaluate ..)

Because I used the AddHatch method before without the need of it.

 

I zoom to the object for speed with the "boundary" command so it does not look at the entire drawing .. try it :) Guess I could call (bpoly pt) too .. but think that speed would still be an issue with many objects on screen.

 

*EDIT .. just tested and it's much slower.

Link to comment
Share on other sites

I zoom to the object for speed with the "boundary" command so it does not look at the entire drawing .. try it :) Guess I could call (bpoly pt) too .. but think that speed would still be an issue with many objects on screen.

 

*EDIT .. just tested and it's much slower.

 

Thanks for confirming, Ron.

Link to comment
Share on other sites

I have a problem with "clone of CAD" - BricsCad

Is it possible to avoid it somehow

 

"; ----- Error around expression -----

(BPOLY "P")

;

; error : no function definition ; expected FUNCTION at [eval]

"

Link to comment
Share on other sites

ok thank you wery much

One additional question.

Function looks great but in my case, polline existing inner block.

Is it possible to somehow extract this outline

Link to comment
Share on other sites

Interesting Ronjonp nice effort, that is one solution but looking at the image is the answer start from setting an actual corner point for a swing line and again is area1 =area2 ? This needs an iteration to rotate till the areas are within a tolerance ie equal.

 

I believe jan_ek you need to confirm a bit more clearly the rules about what you want. Also the image is right to left and Ronjonp code is the other way when I tested ? :lol:

Link to comment
Share on other sites

Hello, I assumed solution below, but the proposed solutions also seem correct

 

attachment.php?attachmentid=63379&cid=1&stc=1

 

FWIW .. A post like this in the beginning helps. The more info you can provide the more likely you'll get the answer you need.

Link to comment
Share on other sites

FWIW to find the opposite point:

 

(defun OppositePtOnCurve ( curve p / dis )
 (vlax-curve-getPointAtDist curve
   (rem
     (+
       (vlax-curve-getDistAtPoint curve p)
       (* 0.5 (setq dis (vlax-curve-getDistAtParam curve (vlax-curve-getEndParam curve))))
     )
     dis
   )
 )
); defun OppositePtOnCurve

 

Test function:

(
 (lambda (x / args p2)
   (and x 
     (setq args (cons (car x) (list (apply 'vlax-curve-getClosestPointTo (append x '(t))))))
     (setq p2 (apply 'OppositePtOnCurve args))
     (entmakex (list (cons 0 "LINE")(cons 10 (cadr args))(cons 11 p2)))
   )
 )
 (nentselp "\nPick a closed curve:")
)

 

OppositePtOnCurve.gif

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...