Jump to content

Recommended Posts

Posted

Hi All,

 

Is it possible to take a random shaped closed polygon or boundary, fill it with vertical lines with an offset of 100 starting from the point furthest to the left just like a hatch would.

 

The reasons for not using a hatch is i want to measure each vertical line and create a list afterwards.

 

Thanks in advance.

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • alanjt

    8

  • DB007

    5

  • Lee Mac

    4

  • BlackBox

    4

Top Posters In This Topic

Posted Images

Posted

The short answer is... Yes.

 

Look into the vla-getboundingbox method to extract your min and max coordinates (X and Y axis).

 

After selecting your closed polyline, programmatically determine your bounding box, then draw your first vertical line, looping your offset(s) until the next polar x coordinate exists outside of your bounding box, then I *believe* an ._extrim command will remove the unwanted segments (outside of your polyline).

 

Edit: In lieu of the ._extrim call you could extract the intersections using vla-insertsectwith method.

 

... Then step into your list function. Done.

 

Hope this helps!

Posted

You could create the hatch and explode it; exploding will turn the hatch into lines.

 

don't quote me cuz I'll deny ever suggesting to explode a hatch

Posted
You could create the hatch and explode it; exploding will turn the hatch into lines.

 

 

Yeah... I guess that would be less typing, huh!? :oops: lol

Posted
You could create the hatch and explode it; exploding will turn the hatch into lines.

 

don't quote me cuz I'll deny ever suggesting to explode a hatch

 

I cant believe I didnt think of that! Is it safe to explode a hatch? or just considered bad practice?

 

I will still look into the vla-getboundingbox command to find the origin of the hatch

 

Thanks both

Posted
Is it safe to explode a hatch?

I'd stand outside the room

 

or just considered bad practice?

Bad practice. Anytime I get a dwg with exploded hatch somebody gets MF'd

Posted
... Is it safe to explode a hatch?

 

 

Absolutely not!!!

 

Doing so will sound an alarm at the White House, you're office will then be swarmed by FBI agents... bad news bears, if you ask me.

 

I am totally kidding! Again today, I just couldn't help myself. :lol:

 

 

I will still look into the vla-getboundingbox command to find the origin of the hatch

 

 

Cool beans; but to clarify, the bounding box is the min (bottom left) and max (upper right) of your overall polyline... the origin of the hatch is located at the centroid of the polyline (which is not always inside of said polyline).

 

Good luck!

Posted
Bad practice. Anytime I get a dwg with exploded hatch somebody gets MF'd

Especially if it's AR-CONC or DOT.

 

 

Something to chew on/get you started...

(defun c:Test (/ p1 p4 i)
 ;; Alan J. Thompson, 09.14.10
 (if (and (setq p1 (getpoint "\nSpecify first corner: "))
          (setq p4 (getcorner p1 "\nSpecify opposite corner: "))
          (not (initget 6))
          (setq i (getdist "\nSpecify incriment distance: "))
     )
   ((lambda (d p2 p3 ang dst)
      (while (> dst (setq d (+ d i)))
        (entmake (list '(0 . "LINE") (cons 10 (polar p1 ang d)) (cons 11 (polar p3 ang d))))
      )
    )
     (- 0. i)
     (list (car p4) (cadr p1))
     (list (car p1) (cadr p4))
     (cond ((> (car p1) (car p4)) pi)
           (0.)
     )
     (abs (- (car p1) (car p4)))
   )
 )
 (princ)
)

or this...

(defun c:Test2 (/ e p1 p4 i)
 ;; Alan J. Thompson, 09.14.10
 (if (and (setq e (car (entsel)))
          (not (initget 6))
          (setq i (getdist "\nSpecify incriment distance: "))
          (not (vla-getBoundingBox (vlax-ename->vla-object e) 'p1 'p4))
          (setq p1 (vlax-safearray->list p1)
                p4 (vlax-safearray->list p4)
          )
     )
   ((lambda (d p2 p3 dst)
      (while (> dst (setq d (+ d i)))
        (entmake (list '(0 . "LINE") (cons 10 (polar p1 0. d)) (cons 11 (polar p3 0. d))))
      )
    )
     (- 0. i)
     (list (car p4) (cadr p1))
     (list (car p1) (cadr p4))
     (abs (- (car p1) (car p4)))
   )
 )
 (princ)
)

Posted (edited)
Absolutely not!!!

 

Doing so will sound an alarm at the White House, you're office will then be swarmed by FBI agents... bad news bears, if you ask me.

 

I am totally kidding! Again today, I just couldn't help myself. :lol:

 

 

Hehe lets hope the FBI cant swim! :) Its only a few straight lines created not dots or arcs so once exploded no one will even know...I wont tell if u dont ;) Just have to make sure the scale doesnt screw things up.

 

I of course will also take a look at all the other suggestions and report back when I've got my head round them.

 

Thanks guys

Edited by DB007
Posted

If you do go the hatch route, you could use a method like this to explode and form a list of each LINE entity.

 

(defun foo (e / l)
 (if (and (eq (type e) 'ENAME) (eq "HATCH" (cdr (assoc 0 (entget e)))))
   (progn
     (command "_.explode" e)
     (while (setq e (entnext e)) (and (eq "LINE" (cdr (assoc 0 (entget e)))) (setq l (cons e l))))
     l
   )
 )
)

 

eg. (selecting a piece of hatch with only lines)

(foo (car (entsel)))

Posted

How about something along these lines:

 

ManualHatch.gif

 

(defun c:test ( / line GroupByNum BBOX D DIS E I LL O UR )
 (vl-load-com)
 ;; © Lee Mac 2010

 (defun line ( p q ) (entmakex (list (cons 0 "LINE") (cons 10 p) (cons 11 q))))

 (defun GroupByNum ( l n / r)
   (setq r (list (car l)))
   
   (if l
     (cons
       (reverse
         (repeat (1- n) (setq l (cdr l) r (cons (car l) r)))
       )
       (GroupByNum (cdr l) n)
     )
   )
 )

 (if
   (and
     (progn
       (while
         (and
           (setq e (car (entsel "\nSelect Closed Object: ")))
           (not (vlax-curve-isClosed e))
         )
         (princ "\n** Object must be Closed **")
       )
       e
     )
     (progn (initget 7)
       (setq d (getreal "\nSpecify Density of Hatch: "))
     )
   )
   (progn
     (vla-getBoundingBox (setq o (vlax-ename->vla-object e)) 'll 'ur)
     (setq bbox (mapcar 'vlax-safearray->list (list ll ur))
            dis (- (caadr bbox) (caar bbox))
              i (* (/ 1. (setq d (1+ d))) dis)
     )
     (
       (lambda ( x p1 p2 / lst l )
         (repeat (fix (* d dis))
           (if
             (and
               (setq lst
                 (GroupByNum
                   (vlax-invoke
                     (setq l
                       (vlax-ename->vla-object
                         (line
                           (polar p1 0. (* (setq x (1+ x)) i))
                           (polar p2 0. (* x i))
                         )
                       )
                     )
                     'IntersectWith o acExtendThisEntity
                   )
                   3
                 )
               )
               (zerop (logand 1 (length lst)))
             )
             (mapcar '(lambda ( x ) (line (car x) (cadr x))) (GroupByNum lst 2))
           )
           (vla-delete l)
         )
       )
      -1 (list (caar bbox) (cadar bbox)) (list (caar bbox) (cadadr bbox))
     )
   )
 )
 (princ)
)

Posted

My five cents worth did something like this once the only suggestion would be to pick the point you want as the control for your vertical lines, it may not always be the bottom left.

 

brilliant as usual Lee

Posted
How about something along these lines:

 

[ATTACH]23083[/ATTACH]

 

(defun c:test ( / line GroupByNum BBOX D DIS E I LL O UR )
(vl-load-com)
;; © Lee Mac 2010

(defun line ( p q ) (entmakex (list (cons 0 "LINE") (cons 10 p) (cons 11 q))))

(defun GroupByNum ( l n / r)
(setq r (list (car l)))

(if l
(cons
(reverse
(repeat (1- n) (setq l (cdr l) r (cons (car l) r)))
)
(GroupByNum (cdr l) n)
)
)
)

(if
(and
(progn
(while
(and
(setq e (car (entsel "\nSelect Closed Object: ")))
(not (vlax-curve-isClosed e))
)
(princ "\n** Object must be Closed **")
)
e
)
(progn (initget 7)
(setq d (getreal "\nSpecify Density of Hatch: "))
)
)
(progn
(vla-getBoundingBox (setq o (vlax-ename->vla-object e)) 'll 'ur)
(setq bbox (mapcar 'vlax-safearray->list (list ll ur))
dis (- (caadr bbox) (caar bbox))
i (* (/ 1. (setq d (1+ d))) dis)
)
(
(lambda ( x p1 p2 / lst l )
(repeat (fix (* d dis))
(if
(and
(setq lst
(GroupByNum
(vlax-invoke
(setq l
(vlax-ename->vla-object
(line
(polar p1 0. (* (setq x (1+ x)) i))
(polar p2 0. (* x i))
)
)
)
'IntersectWith o acExtendThisEntity
)
3
)
)
(zerop (logand 1 (length lst)))
)
(mapcar '(lambda ( x ) (line (car x) (cadr x))) (GroupByNum lst 2))
)
(vla-delete l)
)
)
-1 (list (caar bbox) (cadar bbox)) (list (caar bbox) (cadadr bbox))
)
)
)
(princ)
)

 

Lee, Thanks for this, it looks exactly what I was looking for but when I try to run it the first time i try it it gives me a dialogue box with.. 'Assignment to protected symbol acNative. do you want to enter break loop?'

 

I've had this before when playing around with code with (vl-load-com) and vla* commands but couldnt find a fix.

 

Am i doing something wrong?

 

Thanks

Posted
Nice work, BTW.

 

brilliant as usual Lee

 

Thanks guys, appreciated :)

 

Lee, Thanks for this, it looks exactly what I was looking for but when I try to run it the first time i try it it gives me a dialogue box with.. 'Assignment to protected symbol acNative. do you want to enter break loop?'

 

I've had this before when playing around with code with (vl-load-com) and vla* commands but couldnt find a fix.

 

Am i doing something wrong?

 

Thanks

 

That seems to be quite common, nothing to do with my code however.

 

http://www.theswamp.org/index.php?topic=34881.0

Posted

BTW, whats with the loss of code indentation when code is quoted? Or is it just my browser that is displaying it like that? :unsure:

Posted

 

That seems to be quite common, nothing to do with my code however.

 

http://www.theswamp.org/index.php?topic=34881.0

 

Thanks for the info, nice to know im not just being a dumb ass with a setting somewhere, when I get chance I will check to see if it still happens in 2011. 1st time I clicked No as per the other thread it crashed AutoCAD completely but when I tried it again earlier it was ok. The code works perfectly... Thanks Lee!

 

BTW, whats with the loss of code indentation when code is quoted? Or is it just my browser that is displaying it like that? :unsure:

 

I dont like indents so i took them out! ... Just kidding! :) I have no idea, I just tried to do a reply to that thread again and it did exactly the same thing and im using different machine/operating system now. I always have to view this site in compatability mode in ie8 for some reason though so maybe its that?

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...