turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Close

Visual Basic Customization

- Autodesk Community
- >
- AutoCAD Customization
- >
- Visual Basic Customization
- >
- Re: OCS Coordinate system of Block to UCS or WCS C...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

991 Views, 7 Replies

05-28-2012 07:15 AM

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. See the answer in context.

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:

- calculate the vector from your point of request within the Block (block-definition)
- rotate this vector based on 0,0,0 equal to your BlockReference-Rotation
- scale this vector based on 0,0,0 equal to your BlockReference-Scaling
- move this vector from 0,0,0 to the insertion-point of your blockreference

...assuming that the block is inserted parallel to WCS, so not rotated in 3D that should work.

HTH, - alfred -

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-28-2012 01:18 PM in reply to:
huaxiamengqing

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 -

-------------------------------------------------------------------------

Alfred NESWADBA

Ingenieur Studio HOLLAUS ... www.hollaus.at

-------------------------------------------------------------------------

Alfred NESWADBA

Ingenieur Studio HOLLAUS ... www.hollaus.at

-------------------------------------------------------------------------

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-28-2012 09:37 PM in reply to:
Alfred.NESWADBA

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-29-2012 11:19 PM in reply to:
huaxiamengqing

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:

- calculate the vector from your point of request within the Block (block-definition)
- rotate this vector based on 0,0,0 equal to your BlockReference-Rotation
- scale this vector based on 0,0,0 equal to your BlockReference-Scaling
- move this vector from 0,0,0 to the insertion-point of your blockreference

...assuming that the block is inserted parallel to WCS, so not rotated in 3D that should work.

HTH, - alfred -

-------------------------------------------------------------------------

Alfred NESWADBA

Ingenieur Studio HOLLAUS ... www.hollaus.at

-------------------------------------------------------------------------

Alfred NESWADBA

Ingenieur Studio HOLLAUS ... www.hollaus.at

-------------------------------------------------------------------------

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-30-2012 03:26 AM in reply to:
Alfred.NESWADBA

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-30-2012 07:16 AM in reply to:
Alfred.NESWADBA

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-08-2013 03:48 AM in reply to:
huaxiamengqing

Hi huaxiamengqing,

What is the OCS and WCS parameters you are passing to the functions? Which coordinates are they?

Thanks in advance

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-09-2013 08:04 AM in reply to:
huaxiamengqing

'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

Search This Board

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Post to the Community

Have questions about Autodesk products? Ask the community.

The Knowledge Network

Access a broad range of knowledge to help get the most out of your products and services.

Download & Installation

Getting your SoftwareDownloads & Upgrades

Serial Numbers & Product Keys

Installation & Licensing

Activation & Registration

Network License Administration

Subscription Management

Sign In / Create AccountMaintenance Subscription Help

Desktop Subscription Help

Cloud Service Subscription FAQ

Announcements

Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the *Autodesk Help | Learn | Collaborate* booths in the Exhibit Hall and meet our community team if you get a chance!

- Privacy | Legal Notices & Trademarks | Report Noncompliance | Site map | © Copyright 2014 Autodesk Inc. All rights reserved

Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. Please see the Autodesk Creative Commons FAQ for more information.