Identify

Identify

zph
Collaborator Collaborator
895 Views
9 Replies
Message 1 of 10

Identify

zph
Collaborator
Collaborator

Good day!

 

Please see my function below:

 

;;;;;-----=====     subFunction:  geoCen     =====-----;;;;;


(defun geoCen (ss / cntr nL pL xL yL ss cP cR)

(setq cntr 0 nL () pL () xL () yL ())
(while (< cntr (sslength ss)) (setq nL (cons (ssname ss cntr) nL) cntr (1+ cntr)))

(foreach x nL 
	(cond 
		((= (cdr (assoc 0 (entget x))) "LINE")
			(setq pL (cons (cdr (assoc 10 (entget x))) pL) 
			      pL (cons (cdr (assoc 11 (entget x))) pL))
		)

		((= (cdr (assoc 0 (entget x))) "LWPOLYLINE")
			(foreach y (entget x) (if (= (car y) 10) (setq pL (cons (cdr y) pL))))
		)

		((= (cdr (assoc 0 (entget x))) "CIRCLE")
			(setq cP (cdr (assoc 10 (entget x)))
			      cR (cdr (assoc 40 (entget x)))
			      pL (cons (list (- (car cP) cR) (- (cadr cP) cR)) pL)
			      pL (cons (list (+ (car cP) cR) (+ (cadr cP) cR)) pL))
		)
	) ;cond		
) ;foreach

(foreach x pL (setq xL (cons (car x) xL) yL (cons (cadr x) yL)))
(list (/ (+ (apply 'min xL) (apply 'max xL)) 2) (/ (+ (apply 'min yL) (apply 'max yL)) 2))
) ;geoCen

 

For some reason, "CIRCLE"s aren't accounted for when the overall routine is executed and its respective points aren't considered.  "LINE"s and "LWPOLYLINE"s are.

 

I've attached the entire routine, if you need it, for context.

0 Likes
Accepted solutions (1)
896 Views
9 Replies
Replies (9)
Message 2 of 10

ВeekeeCZ
Consultant
Consultant

I am not very much clever from your question... but I think that CIRCLE's points are treated same as LINE's or PLINE's. I tried that and it always adds those two points into pL list correnctly. Only differece I see that from LINE you take (x y z), from others just (x y). But it probably does not mind to other algoritm.

 

Not sure why you taking (xP-xR, yP-yR) and (yP+R, yP+yR)... it's not a square... these point does not even lie on circle.

 

I would consinder using (entget) for second selection because prompt "Select objects: " is very confusing in this case.

 

And for MOVE command consider (trans) function for translation coords WCS to UCS.

0 Likes
Message 3 of 10

zph
Collaborator
Collaborator
" (xP-xR, yP-yR) and (yP+R, yP+yR)"

You are correct that I am essentially 'making' a square, but the purpose is to identify the 'extents' of the circle (which are the quadrants). Before this I identified each quadrant coordinate point (4 of them). I realized I could combine the 4 points into two points and still retain the important information. However, at this point, I may skip this step altogether and directly place the individual x and y values into xL and yL, respectively.
0 Likes
Message 4 of 10

zph
Collaborator
Collaborator

I've attached some pictures to describe what I want to happen and what is happening.

 

The before correct picture is the sample of objects (one of each line, polyline, and circle).

 

After correct picture shows the location of all the objects at the geometric center of the 'border' polyline (and in this case is the center of the circle because the circle's quadrants contain the minimum and maximum x and y values.

 

The after incorrect picture shows what is occuring when I run my routine.  I highlited the circle so you can see that the center of the circle is not at the geometric center of the 'border'.  Instead the line and polyline's combined geometric center is used.

 

Does this help?

 

EDIT:  I am using the term 'geometric center'.  In the routine, it is the 'midpoint' between two points containing the minimum x and y and maximum x and y values from all the points contained in a selection set.

0 Likes
Message 5 of 10

zph
Collaborator
Collaborator

Based upon your comment, I've looked into the TRANS function, but I don't understand why you feel I ought to use it.

 

EDIT:  I found this bit in the help files:

 

"...If you want your application to send coordinates in the WCS, OCS, or DCS to AutoCAD commands, you must first convert them to the UCS by calling the TRANS function."

 

However, the routine already functions with line and polylines without using the TRANS function.  Would TRANS be needed for the circle's point?

0 Likes
Message 6 of 10

ВeekeeCZ
Consultant
Consultant

@zph wrote:

Based upon your comment, I've looked into the TRANS function, but I don't understand why you feel I ought to use it.

 

EDIT:  I found this bit in the help files:

 

"...If you want your application to send coordinates in the WCS, OCS, or DCS to AutoCAD commands, you must first convert them to the UCS by calling the TRANS function."

 

However, the routine already functions with line and polylines without using the TRANS function.  Would TRANS be needed for the circle's point?


Not sure if you ever used UCS. If you not, then the program will work correctly. But if you rotate current coordinate system (to UCS), then your program fails. And the only reason is because of MOVE command. Whole algorithm uses WCS (world coord system), but MOVE command uses UCS (user coord system). So to fix this, you convert WCS point into UCS and MOVE command it moves into correct coordinates.

 

See THIS very up to date thread where the program fails just because of wrong usage of WCS vs. UCS.

Message 7 of 10

ВeekeeCZ
Consultant
Consultant

@zph wrote:

 

 

EDIT:  I am using the term 'geometric center'.  In the routine, it is the 'midpoint' between two points containing the minimum x and y and maximum x and y values from all the points contained in a selection set.


If I am understanding correctly, you are doing bounding box... and getting the middle of that. 

Are you familiar with  (vla-GetBoundingBox (vlax-ename->vla-object en) 'PtArMin 'PtArMax) function?

 

You can also try Lee Mac's subfunction HERE where he applies this on selection set.

 

Message 8 of 10

ВeekeeCZ
Consultant
Consultant
Accepted solution

@zph wrote:

I've attached some pictures to describe what I want to happen and what is happening.

 

The before correct picture is the sample of objects (one of each line, polyline, and circle).

 

After correct picture shows the location of all the objects at the geometric center of the 'border' polyline (and in this case is the center of the circle because the circle's quadrants contain the minimum and maximum x and y values.

 

The after incorrect picture shows what is occuring when I run my routine.  I highlited the circle so you can see that the center of the circle is not at the geometric center of the 'border'.  Instead the line and polyline's combined geometric center is used.

 

Does this help?

 


Ok, I tried that 3 times and always get a perfect mid to mid result. So it must be environment. Try to turn off ORTHO, SNAP... 

Message 9 of 10

zph
Collaborator
Collaborator

I tried my routine on a fresh file and it worked. So, yes, the problem isn't with my code, necessarily.

Just curious, is there a routine or standard command that returns all the system variable names with their values within a drawing?

To put this in context, the file I was testing this routine in is one of a couple custom .dwt files. I want to compare the system variables of these custom templates to the AutoCAD's standard acad.dwt file.

0 Likes
Message 10 of 10

ВeekeeCZ
Consultant
Consultant

@zph wrote:

...
Just curious, is there a routine or standard command that returns all the system variable names with their values within a drawing?
...


Probably the best is to use the Express Tools, the SYSVDLG command. This command allows you export all the sysvar into external file... comparation with other file is very simple then. 

 

Or you can type SETVAR command, then "?", then "*". But this is not as comfortable as above.