Jump to content

Recommended Posts

Posted

I have some code that creates a closed polyline. It may have say 40 vertices.

At the end of my code I want to turn my closed pline into a region

just using :

(command "_.REGION" Ent "" )

However it always comes up with the message:

 

All open edges cannot be colinear.

0 loops extracted.

0 Regions created.

 

I checked for duplicate shapes and there are none.

Has anyone had a similar problem making a region?

The strange thing is it works when I make region manually

Is there a fix for it?

thanks

Posted

Hmmm, I am not getting that problem - could you post a sample drawing of the polyline you are attempting to "region-ise"... :P

Posted

Actually now I think the REGION command is not the problem - its the object entity value that I am using ie not the one I had in mind. So its my code that needs adjusting.

I have tried all kinds of ideas but now I've exhausted possibilities.

I have attached my code. In last few lines of the code there is

(setq FinalOutline (entlast)) this is where I think the problem is- it just will not hold the entity value of the polyline that is drawn -it has some other unknown entity.

 

****Edit: - that entity I have discovered is the last circle in the selection set. Instead of the polyline turning into a region the circle does! Question is how can I make the new pline shape turn into a region??

 

 

To use it first draw a rectangle roughly 1000 x 1000 with some circles in rows inside it.

(defun c:RowAreas10 (/ enaPline ObjName LowLeft UpRight

LowRight UpLeft TopCl BotCl

lEnt pt1 pt2 lDat

test flag ss tCirc

subSs total ent subSs_lst

cLst Rad LenExtrusion

TempPtRt en3R IntPointRt ExtPtR

ExtPtTopR ExtPtBotR CircTopR CircBotR

en4R IntPointTopR en5R

IntPointBotR en6R en7R

en8R TempPtLt en3L IntPointLt

ExtPtL ExtPtTopL ExtPtBotL CircTopL

CircBotL en4L IntPointTopL

en5L IntPointBotL en6L

en7L en8L test FinalOutline)

(vl-load-com)

(setvar "osmode" 0)

(setq enaPline (car (entsel "\nSelect rectangle outline : ")))

(setq ObjName (vlax-ename->vla-object enaPline))

(vla-GetBoundingBox ObjName 'LowLeft 'UpRight)

(setq LowLeft (vlax-safearray->list LowLeft)

UpRight (vlax-safearray->list UpRight)

LowRight(list(car UpRight)(cadr LowLeft))

UpLeft (list(car LowLeft)(cadr UpRight))

);setq

;Find vertical centreline rectangle

(setq TopCl (mapcar '+ UpLeft (mapcar '/ (mapcar '- UpRight UpLeft) '(2.0 2.0 2.0))));Top of centreline

(setq BotCl (mapcar '+ LowLeft (mapcar '/ (mapcar '- LowRight LowLeft) '(2.0 2.0 2.0))));Bottom of centreline

(command "LINE" TopCl BotCl "");draw temp line

(setq lEnt (entlast))

(if(and

;;; (setq lEnt (car (entsel "\n>>>...Select Vertical Line...>>>: ")))

(eq "LINE" (cdadr (entget lEnt)))

(null (redraw lEnt 3))

 

(setq pt1 (getpoint "\n>>>...Pick First Point of Window over circles...>>>: "))

(null (initget 32))

(setq pt2 (getcorner pt1 "\n>>>...Pick Second Point of Window over circles...>>>>: "))

(null (redraw lEnt 4)))

(progn

(setq lDat (list (cdr (assoc 10 (entget lEnt)))

(cdr (assoc 11 (entget lEnt)))))

(entdel lEnt)

(repeat 2

(setq test 1)

(if (setq ss (ssget "_c" pt1 pt2 (list '(0 . "CIRCLE")(cons -4 (if flag ">=,*,*" "

(cons 10

(append

(list

(apply

(if flag 'max 'min)

(mapcar 'car lDat)))

'(0 0))))))

(while (not (zerop (sslength ss)))

(setq tCirc (ssname ss 0))

(if (setq subSs (ssget "_c" pt1 pt2 (list (cons 0 "CIRCLE")

(cons -4 (if flag ">=,=,*" "

(cons 10

(append

(list

(apply

(if flag 'max 'min)

(mapcar 'car lDat)))

(cddr (assoc 10 (entget tCirc))))))))

(progn

(setq total 0.0)

(foreach ent (setq subSs_lst

(vl-remove-if 'listp

(mapcar 'cadr

(ssnamex subSs))))

(setq total (+ total (vla-get-Area

(vlax-ename->vla-object ent)))))

(setq cLst(car

(vl-sort

(mapcar '(lambda (x) (cdr (assoc 10 (entget x)))) subSs_lst)

'(lambda (x1 x2) (

Rad

(car(vl-sort

(mapcar '(lambda (x) (cdr (assoc 40 (entget x)))) subSs_lst)

'(lambda (r1 r2) (> r1 r2)))))

(setq LenExtrusion 800);test length of extrusion

(if flag

(progn

(setq TempPtRt (polar cLst 0 3000));temp pt to right

(command "_.pline" cLst TempPtRt "")

(setq en3R (entlast))

(setq IntPointRt (safearray-value(variant-value(vla-intersectwith

(vlax-ename->vla-object enaPline )

(vlax-ename->vla-object en3R)acExtendNone)))

);setq

(setq ExtPtR (polar IntPointRt 0 LenExtrusion))

(setq ExtPtTopR (polar ExtPtR (* 0.5 pi) rad))

(setq ExtPtBotR(polar ExtPtR (* 1.5 pi) rad))

(setq CircTopR (polar cLst (* 0.5 pi) rad))

(setq CircBotR(polar cLst (* 1.5 pi) rad))

(command "_.pline" CircTopR ExtPtTopR "")

(setq en4R (entlast))

(setq IntPointTopR

(safearray-value(variant-value(vla-intersectwith

(vlax-ename->vla-object enaPline )

(vlax-ename->vla-object en4R)acExtendNone)))

);setq

(command "_.pline" CircBotR ExtPtBotR "");temp bottom pline

(setq en5R (entlast))

(setq IntPointBotR

(safearray-value(variant-value(vla-intersectwith

(vlax-ename->vla-object enaPline)

(vlax-ename->vla-object en5R)acExtendNone)))

);setq

(command "_.pline" IntPointBotR ExtPtBotR "")

(setq en6R (entlast))

(command "_.pline" IntPointTopR ExtPtTopR "")

(setq en7R (entlast))

(command "_.pline" ExtPtTopR ExtPtBotR "")

(setq en8R (entlast))

(entdel en4R)

(entdel en5R)

(entdel en3R)

(command "BREAK" enaPline IntPointBotR IntPointTopR)

(command "_.PEDIT" enaPline "_JOIN" en6R en7R en8R "" "")

);progn

);if

 

(if (not flag)

(progn

(setq TempPtLt (polar cLst pi 3000));temp pt to left

(command "_.pline" cLst TempPtLt "")

(setq en3L (entlast))

(setq IntPointLt (safearray-value(variant-value(vla-intersectwith

(vlax-ename->vla-object enaPline )

(vlax-ename->vla-object en3L)acExtendNone)))

);setq

(setq ExtPtL (polar IntPointLt pi LenExtrusion))

(setq ExtPtTopL (polar ExtPtL (* 0.5 pi) rad))

(setq ExtPtBotL(polar ExtPtL (* 1.5 pi) rad))

(setq CircTopL (polar cLst (* 0.5 pi) rad ))

(setq CircBotL(polar cLst (* 1.5 pi) rad))

(command "_.pline" CircTopL ExtPtTopL "")

(setq en4L (entlast))

(setq IntPointTopL

(safearray-value(variant-value(vla-intersectwith

(vlax-ename->vla-object enaPline )

(vlax-ename->vla-object en4L)acExtendNone)))

);setq

(command "_.pline" CircBotL ExtPtBotL "");temp bottom pline

(setq en5L (entlast))

(setq IntPointBotL

(safearray-value(variant-value(vla-intersectwith

(vlax-ename->vla-object enaPline)

(vlax-ename->vla-object en5L)acExtendNone)))

);setq

(command "_.pline" IntPointBotL ExtPtBotL "")

(setq en6L (entlast))

(command "_.pline" IntPointTopL ExtPtTopL "")

(setq en7L (entlast))

(command "_.pline" ExtPtTopL ExtPtBotL "")

(setq en8L (entlast))

(entdel en4L)

(entdel en5L)

(entdel en3L)

(command "BREAK" enaPline IntPointBotL IntPointTopL)

(command "_.PEDIT" enaPline "_JOIN" en6L en7L en8L "" "")

);progn

);if

(mapcar '(lambda (x) (ssdel x ss)) subSs_lst)

;;; (princ (strcat "\nRow " (itoa test)

;;; "; MinXCtr: " (vl-princ-to-string (car cLst))

;;; " MaxRad = " (vl-princ-to-string (car Rad))

;;; " => " " Total = "(rtos total)

;;; "\n-----------------------------------------"))

);progn

);if

(ssdel tCirc ss)

(setq test (1+ test))))

(and (not flag))

(setq flag T))

);progn

);if

(setq FinalOutline (entlast));capture new polyline entity

(command "_.REGION" FinalOutline "" );make region

(princ )

);defun

 

 

 

Posted

I have found the solution - all that was needed was to make a "REGENALL"

Don't you just hate when the solution is so easy and staring in the face!!!

Posted
I have found the solution - all that was needed was to make a "REGENALL"

Don't you just hate when the solution is so easy and staring in the face!!!

 

 

Sorry I haven't had the time to look over this - but I am glad that you found the solution :)

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