BUrBaKy Posted December 21, 2010 Posted December 21, 2010 Hi there. Here's my problem. I draw a couple of circles, and i want to calculate the centroid of them. I select them using group codes filters. So far so good. But the coordonates i get for their centers, are in WCS, and i need them in UCS. I found something about the "Utility.TranslateCoordinates" function, but i have problems using it in my case. Here's the code. Public Sub CalcImbinare() Dim entObj As AcadEntity Dim ssetObj As AcadSelectionSet Dim grpCode(0) As Integer Dim dataVal(0) As Variant grpCode(0) = 0 dataVal(0) = "CIRCLE" On Error Resume Next Set ssetObj = ThisDrawing.SelectionSets.Add(SetName) If Err.Number <> 0 Then Set ssetObj = ThisDrawing.SelectionSets.Item(SetName) End If ssetObj.Clear Set ssetObj = ThisDrawing.SelectionSets.Add("SS01") ssetObj.SelectOnScreen grpCode, dataVal ' SELECTION OF THE CIRCLES IS COMPLETE ' NOW I"M TRYING TO USE THE CIRCLE COORDONATES IN MY CALCULATIONS, ' BUT I GET THEM IN WCS, AND I NEED THEM IN UCS Dim xg, yg As Double Dim pct As Variant ' I TRIED ALSO " pcs (0 to 2) as Double" TYPICAL FOR A POINT VARIABLE ' STILL THE SAME RESULT xg = 0 : yg = 0 : For i = 0 To ssetObj.Count - 1 Set pct = ThisDrawing.Utility.TranslateCoordinates(ssetObj.Item(i).Center, acWorld, acOCS, True) xg = xg + pct(0) yg = yg + pct(1) Next i xg = xg / ssetObj.Count yg = yg / ssetObj.Count End Sub The result is that nothing happens, the variable "pct" doesn't get any values. Thanks in advance! Quote
JPlanera Posted December 21, 2010 Posted December 21, 2010 I created a new UCS at 10,10,10 Drew a circle made it a region and looked at its massprops... The value i got for centroid was in UCS.. what is your process? Quote
BUrBaKy Posted December 21, 2010 Author Posted December 21, 2010 so you say i should lock the circles and then get their center coordinates? i'll try that too Quote
JPlanera Posted December 21, 2010 Posted December 21, 2010 Well im not sure what you are doing, but if it is just centers of circles you are after, whatever UCS you have current, the coordinate values are displayed in the status bar at the bottom left of your screen.... Quote
SEANT Posted December 21, 2010 Posted December 21, 2010 See if this works any better. Public Sub CalcImbinare() Dim entObj As AcadEntity Dim ssetObj As AcadSelectionSet Dim grpCode(0) As Integer Dim dataVal(0) As Variant grpCode(0) = 0 dataVal(0) = "CIRCLE" On Error Resume Next Set ssetObj = ThisDrawing.SelectionSets.Add("SS01") If Err.Number <> 0 Then Set ssetObj = ThisDrawing.SelectionSets.Item("SS01") ssetObj.Clear End If On Error GoTo 0 ssetObj.SelectOnScreen grpCode, dataVal ' SELECTION OF THE CIRCLES IS COMPLETE ' NOW I"M TRYING TO USE THE CIRCLE COORDONATES IN MY CALCULATIONS, ' BUT I GET THEM IN WCS, AND I NEED THEM IN UCS Dim xg, yg As Double Dim pct As Variant Dim i As Integer Dim entCirc As AcadCircle ' I TRIED ALSO " pcs (0 to 2) as Double" TYPICAL FOR A POINT VARIABLE ' STILL THE SAME RESULT xg = 0: yg = 0: For i = 0 To ssetObj.Count - 1 Set entCirc = ssetObj.Item(i) 'Explicit casting is not always neccessary, but safe pct = ThisDrawing.Utility.TranslateCoordinates(entCirc.Center, acWorld, acUCS, 0) xg = xg + pct(0) yg = yg + pct(1) Next i xg = xg / ssetObj.Count yg = yg / ssetObj.Count End Sub Quote
BUrBaKy Posted December 22, 2010 Author Posted December 22, 2010 Wow, it does work. Cool. Nice anwser, slight change but accurate! very nice, thank you very much! Problem solved! Quote
Recommended Posts
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.