Hi, everyone!
I want to know how to transform OCS Coordinate of A block object to UCS or WCS Coordinate .
It's Block's OCS Coordinate not other objects.
I will appreciate for your suggestions.
Solved! Go to Solution.
Solved by Alfred.NESWADBA. Go to Solution.
Hi,
look to this method (if you are working with VBA) within ThisDrawing.Utility:
Function TranslateCoordinates(Point, FromCoordSystem As AcCoordinateSystem, ToCoordSystem As AcCoordinateSystem, Displacement As Long, [OCSNormal])
- alfred -
Thank you, alfred ! I know this function. and I know how to use it to transform a 3DPolyline's OCS to UCS. but I can't find the last arguments of the function When I use it to transform Block 's OCS.
In fact I have never found out the meaning of the last two arguments of this function.
I am eager to more information about this function and I want you give an example about BlockObject's transform. Thank you again.
Hi,
ok, I understand the problem now as you can convert UCS to WCS and to ScreenCS, but not directly to Block-CS. The problem is that Block-CS differs from the other ones by having a scaling built in and that does not work (at least not with this function).
If you have dotNET, you have access to the BlockReference-Transformation-Matrix, that makes it more easy to get the info's of points within a BlockReference transfered to WCS.
The direction I would go now with VBA is:
...assuming that the block is inserted parallel to WCS, so not rotated in 3D that should work.
HTH, - alfred -
Yes,I am writing code toward this direction.It's more difficult than you say. The code is short but the calculation of the mathematical is too complex. But I think I can make it. I will share it when I get it completed.
Thank you alfred. You are knowledgeble !
I think I have more questions to ask later.
I have worked it out. Share it below.
'*************************************************************************** '块的OCS转WCS坐标 'B是块对象,ocsp是一个变体存储遍历块获得块内OCS坐标,WCsp 返回OCSp对于的世界坐标 '江河梦小组 华夏梦清 QQ 772671249 rtx 61692 '2012.5.30 '仅适用于XY面上块对象 '*************************************************************************** Public Sub BOcsToWcs(b As AcadBlockReference, ocsp, Wcsp() As Double) Dim X As Double, Y As Double, R As Double, P As Double, Z As Double Dim WcsX As Double, WcsY As Double, WcsZ As Double Dim Instrpoint As Variant, V1 As Integer, V2 As Integer Const Pi As Double = 3.14159265358979 X = b.XScaleFactor Y = b.YScaleFactor Z = b.ZScaleFactor R = b.Rotation Instrpoint = b.InsertionPoint '所求均为与x正半轴夹角 If ocsp(0) > 0 And ocsp(1) = 0 Then 'x正半轴 R = R + 0 ElseIf ocsp(0) > 0 And ocsp(1) > 0 Then '第一象限 R = R + Atn(ocsp(1) / ocsp(0)) ElseIf ocsp(0) = 0 And ocsp(1) > 0 Then 'y正半轴 R = R + Pi / 2 ElseIf ocsp(0) < 0 And ocsp(1) > 0 Then '第二象限 R = R + Atn(ocsp(1) / ocsp(0)) + Pi ElseIf ocsp(0) < 0 And ocsp(1) > 0 Then 'x负半轴 R = R + Pi ElseIf ocsp(0) < 0 And ocsp(1) < 0 Then '第三象限 R = R + Atn(ocsp(1) / ocsp(0)) + Pi ElseIf ocsp(0) = 0 And ocsp(1) < 0 Then 'y负半轴 R = R + Pi * 3 / 2 ElseIf ocsp(0) > 0 And ocsp(1) < 0 Then '第四象限 R = R + Atn(ocsp(1) / ocsp(0)) + 2 * Pi Else '原点 R = R + 0 End If P = (ocsp(0) ^ 2 + ocsp(1) ^ 2 + ocsp(2) ^ 2) ^ 0.5 '求的极坐标半径 '获得相对于插入点的世界坐标 WcsX = P * Cos(R) * X: WcsY = P * Sin(R) * Y: WcsZ = P * ocsp(2) '获得世界坐标 Wcsp(0) = WcsX + Instrpoint(0) Wcsp(1) = WcsY + Instrpoint(1) Wcsp(2) = WcsZ + Instrpoint(2) End Sub Private Sub CommandButton1_Click() '测试代码 '建立一个图块,里面包含一个点,测试这个点 Dim Wcsp(0 To 2) As Double Dim ocsp Dim Bref As AcadBlockReference Dim Myent As AcadEntity On Error Resume Next Me.Hide ThisDrawing.StartUndoMark Do ThisDrawing.Utility.GetEntity Bref, pick, "选择测试块" DoEvents For Each Myent In ThisDrawing.Blocks(Bref.Name) If Myent.ObjectName = "AcDbPoint" Then ocsp = Myent.Coordinates BOcsToWcs Bref, ocsp, Wcsp ' For i = 0 To 2 ' Debug.Print Wcsp(i) ' Next ' Debug.Print "***********" ThisDrawing.ModelSpace.AddCircle Wcsp, 500 End If Next Debug.Print Err.Number & "--" & Err.Description Loop While Err.Number <> -2147352567 ThisDrawing.EndUndoMark ThisDrawing.SendCommand "U" & Chr(13) Me.Show 0 End Sub
The code in the sub of button is just for a test. In the test, you should use the dwg attachment. Run the test,select a block , it would use the transformed WCS point build circles.
Thank you alfred.
Hi huaxiamengqing,
What is the OCS and WCS parameters you are passing to the functions? Which coordinates are they?
Thanks in advance
'B是块对象,ocsp是一个变体存储遍历块获得块内OCS坐标,WCsp 返回OCSp对于的世界坐标
you can translate this sentence by gogle.
b is a block ocs is a array of pointxyz in block, wcsp is the returned wcsp point
Can't find what you're looking for? Ask the community or share your knowledge.