PDA

View Full Version : Determining centre of Object / A marked position on screen without user input


tany0070
2007-03-06, 04:00 AM
does anyone know how one can determine the position of a point (like center of a square, circle or a point marked with a cross) without having human intercession for inputing/selecting the point?? if possible please help also with selecting program drawn stuff like mirror objects without user inputing their positions

thanks.

tany0070
2007-03-08, 07:20 AM
so am i to assume that no one knows a solution to this problem?? i really need this so that my automation program can run more smoothly without user input(plus less likelihood of input error). so if anyone does know anything about this do reply. thanks

jaseh
2007-03-08, 09:05 AM
The code below will return the centre of a selected circle or the insertion point of a point entity or block etc. a square would be much more difficult as it probably would consist of a polyline and therefore only vertex points could be returned with further coding

(cdr(assoc 10 (entget (car (entsel)))))

abdulhuck
2007-03-08, 01:29 PM
so am i to assume that no one knows a solution to this problem??
Dear friend,

I assume no one understand your questions! :)

does anyone know how one can determine the position of a point (like center of a square, circle or a point marked with a cross) without having human intercession for inputing/selecting the point?? if possible please help also with selecting program drawn stuff like mirror objects without user inputing their positions
Tips:

If you have any specific requirement, please outline it here. (For example, "I wish to select all the circles in a drawing and assign a unique number in centre of each circle." This is possible without user input)
You will have to provide your available data, so that others can figure out what is missing and how the task can be accomplished.
If you feel it difficult to explain in words, provide some sample drawings, illustrations etc.
Please don't assume that "no one knows a solution". There are a lot of expert people here spending their time to help all of us. Please be specific in your questions, and you will get a solution, for sure (it's from my experience).

Best regards

Abdul Huck

Adesu
2007-03-09, 01:20 AM
Hi tany0070,
This code only for circle,test it if you want know.


(defun c:test (/ cp dis etype p1 p2 p3 p4 rad ss sse)
(if
(setq ss (car (entsel "\nSelect an circle object")))
(progn
(setq sse (entget ss))
(setq etype (cdr (assoc 0 sse)))
(if
(= etype "CIRCLE")
(progn
(setq cp (cdr (assoc 10 sse)))
(setq rad (cdr (assoc 40 sse)))
(setq dis (* rad 0.1))
(setq p1 (polar cp pi (/ dis 2.0)))
(setq p2 (polar p1 0 dis))
(setq p3 (polar cp (* pi 0.5)(/ dis 2.0)))
(setq p4 (polar p3 (* pi 1.5) dis))
(command "_line" p1 p2 "")
(command "_line" p3 p4 "")
) ; progn
(alert "\nInvalid selected object,it's not circle")
) ; if
) ; progn
) ; if
(princ)
) ; defun


does anyone know how one can determine the position of a point (like center of a square, circle or a point marked with a cross) without having human intercession for inputing/selecting the point?? if possible please help also with selecting program drawn stuff like mirror objects without user inputing their positions

thanks.

aaronic_abacus
2007-03-09, 02:32 AM
Use zoom extents, and system variables VIEWCTR and VIEWSIZE

tany0070
2007-03-09, 02:36 AM
thank you all for the replies and sorry for the harsh words before, its just that this thread was left untouched for a while and i was kind of getting inpatient as this code is like the start of my program (though will be used again later) and without it i can't really do anything.

just to illustrate further, i'll explain with the aid of the attached image. what i want the program to do is
1) automatically select the point marked marked by the 2 green lines
2) user selects any of the yellow objects
3) program mirrors the selected object along vertical green line and arrays the original and mirrored object around the chosen point.

i will need help with 1) so if anyone has any ideas as to how i can be done, do share it with me

thank you

.T.
2007-03-09, 02:50 AM
thank you all for the replies and sorry for the harsh words before, its just that this thread was left untouched for a while and i was kind of getting inpatient as this code is like the start of my program (though will be used again later) and without it i can't really do anything.

just to illustrate further, i'll explain with the aid of the attached image. what i want the program to do is
1) automatically select the point marked marked by the 2 green lines
2) user selects any of the yellow objects
3) program mirrors the selected object along vertical green line and arrays the original and mirrored object around the chosen point.

i will need help with 1) so if anyone has any ideas as to how i can be done, do share it with me

thank you

Hi,

If you use SSGET and ENTGET to get the data for the two lines, then extract the endpoints using the 10 and 11 dxf codes, you can use the INTERS function with those endpoints to determine where they intersect.

Let us know if you need help doing that.

tany0070
2007-03-09, 03:32 AM
Hi,

If you use SSGET and ENTGET to get the data for the two lines, then extract the endpoints using the 10 and 11 dxf codes, you can use the INTERS function with those endpoints to determine where they intersect.

Let us know if you need help doing that.
thank you for the idea =) may i now post another question for help. i noted that the dxf codes are stored as list so if i want to read out the data for within, like the layer name etc, using the nth function, ie. nth to get layout data then nth again to attempt getting the layer name something like that, an (error: bad list: "outline") will be prompt can someone please help and suggest how i may retrieve the data. thanks

.T.
2007-03-09, 04:21 AM
thank you for the idea =) may i now post another question for help. i noted that the dxf codes are stored as list so if i want to read out the data for within, like the layer name etc, using the nth function, ie. nth to get layout data then nth again to attempt getting the layer name something like that, an (error: bad list: "outline") will be prompt can someone please help and suggest how i may retrieve the data. thanks

I have to run to class, but start here...

(cdr (assoc 10 ent))

[ent being a symbol that contains the entity data you obtained through ENTGET or SSNAME]

would return a list like (10.00 15.15 0.0) [example] this is fine for the arguments for INTERS.

It might help if you also post your code as we go along so we make sure we are on the same page and understand each other.

I'll be back after a while.

aaronic_abacus
2007-03-09, 04:33 AM
SSNAME gets the entity name in a selection set and
ENTGET gets the DXF group entitiy codes.

tany0070
2007-03-09, 04:34 AM
I have to run to class, but start here...

(cdr (assoc 10 ent))

[ent being a symbol that contains the ename you obtained through ENTGET or SSNAME]

would return a list like (10.00 15.15 0.0) [example] this is fine for the arguments for INTERS.

It might help if you also post your code as we go along so we make sure we are on the same page and understand each other.

I'll be back after a while.
thanks, alot, really. =>

.T.
2007-03-09, 08:36 AM
With ssget, what you are trying to do is gather the entities that you want to work with and put them in a selection set. The "x" tells ssget to look at everything in the database (drawing), and in this case, you are filtering through all of the entities and only selecting entities that are on the "layername" layer.

(cdr (assoc ... is for extracting data from an entity. As an example, let's set a symbol called ent to the first entity in the selection set like this:

(setq ent (entget (ssname ss2 0)))

It will return a list something like:

((-1 . <Entity name: 7efd9470>) (0 . "LINE") (330 . <Entity
name: 7efbfcf8>) (5 . "82E") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
"layername") (100 . "AcDbLine") (10 5878.41 10655.5 0.0) (11 6133.21 10656.6 0.0) (210
0.0 0.0 1.0))

In this example, when we use (cdr (assoc 8 ent)) it will return "layername" because the line is on layer layername. The 8 is the dxf code that is associated with layer. You can find a list of dxf codes and what they reference in the developer's guide. You will be interested in the dxf codes 10 and 11 to extract the endpoints of the lines. Maybe something like:
(setq s2 (ssget "x" '((8 . "layername")))) ; for this example we will say that there are
; only the 2 lines on layer layername
(setq ent1 (entget (ssname ss2 0))); gets data for the first entity in the selection set
(setq ent2 (entget (ssname ss2 1))); gets data for the second entity in the selection set
(setq pt1 (cdr (assoc 10 ent1))); returns and stores the first point in line 1
(setq pt2 (cdr (assoc 11 ent1))); returns and stores the second point in line 1
(setq pt3 (cdr (assoc 10 ent2))); returns and stores the first point in line 2
(setq pt4 (cdr (assoc 11 ent2))); returns and stores the second point in line 2

Then we can use the INTERS function to get the intersection:

(setq center_point (inters pt1 pt2 pt3 pt4))

tany0070
2007-03-09, 08:53 AM
thank you i believe my problems solved at least for now, all your help are greatly appreciated as i m still very new to this language.