VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Reply
Message 1 of 4
Anonymous
1776 Views, 3 Replies

ucs/wcs

i have a drawing which user change origin by ucs
when i get data through acdbentity, returned coordinate are in wcs
how i could change them to ucs?
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Anonymous

Read up on this function:
(trans pt from to [disp])
Arguments

pt
A list of three reals that can be interpreted as either a 3D point or a 3D
displacement (vector).

from
An integer code, entity name, or 3D extrusion vector identifying the
coordinate system in which pt is expressed. The integer code can be one of
the following:

0 World (WCS)

1 User (current UCS)

2 If used with code 0 or 1, this indicates the Display Coordinate System
(DCS) of the current viewport. When used with code 3, it indicates the DCS
of the current model space viewport.

3 Paper space DCS (used only with code 2)

to
An integer code, entity name, or 3D extrusion vector identifying the
coordinate system of the returned point. See the from argument for a list of
valid integer codes.

disp

If present and is not nil, this argument specifies that pt is to be
treated as a 3D displacement rather than as a point.

Paul

wrote in message news:6389393@discussion.autodesk.com...
i have a drawing which user change origin by ucs
when i get data through acdbentity, returned coordinate are in wcs
how i could change them to ucs?
Message 3 of 4
Anonymous
in reply to: Anonymous

Thanks
just please write a code for your suggestion
i draw a line from 10,10 to 20,20
run ucs command,and select origin, as 10,10
now when i use list command i have a line from 0,0 t0 10,10
but when i use acdbline.startpoint(0) and acdbline.startpoint(1) i have 10,10
Dim newsset As AcadSelectionSet
On Error Resume Next
Set newsset = ThisDrawing.SelectionSets.Add("newselset")
If Err.Number <> 0 Then
ThisDrawing.SelectionSets.Item("newselset").Delete
Set newsset = ThisDrawing.SelectionSets.Add("newselset")
End If
my code :

sub ssmethod
ReDim ssobjs(0 To ThisDrawing.ModelSpace.Count - 1) As AcadEntity
Dim i As Integer
For i = 0 To ThisDrawing.ModelSpace.Count - 1
Set ssobjs(i) = ThisDrawing.ModelSpace.Item(i)
Next

newsset.AddItems ssobjs
GoSub featurerecognition
newsset.Clear


Exit Sub

featurerecognition:
nf = newsset.Count
'***********************************************************************************8
'getting feature data
Dim linef As AcadLine
For i = 0 To nf - 1
Select Case UCase$(ssobjs(i).ObjectName)
Case "ACDBLINE"
nff = nff + 1
Set linef = ThisDrawing.ModelSpace.Item(i)
MsgBox "entity is:" & linef.startpoint(0)& " stx=" & Str$(fr(nff).stx) & " sty=" & linef.startpoint(1) & " enx=" & linef.endpoint(0) & " eny=" & linef.endpoint(1)
End Select
Next i
return

end sub

please correct this code as i could have startpoint and end point of entity in ucs!
Message 4 of 4
Anonymous
in reply to: Anonymous

The process is fairly easy. The hard part is keep one's mind straight as to what coordinate system the data is and what coordinate system you need to convert to. I believe in general, data you get from a VBA routine is in WCS. Data you want to use to create needs to be in the current UCS. The Utility.TranslateCoordinates converts a coordinate in either direction. You will need to read the AutoCAD VBA Help to make sure the argument order is correct.

If PickedPoint1 is a coordinate then:

ThisDrawing.Utility.TranslateCoordinates(PickedPoint1, acWorld, acUCS, False) returns PickedPoint1 converted from acWorld to acUCS

Thus,

PickedPoint1 = ThisDrawing.Utility.TranslateCoordinates(PickedPoint1, acWorld, acUCS, False)

changes PickedPoint1 from WCS to UCS.

going the other way:

ThisDrawing.Utility.TranslateCoordinates(PickedPoint1, acUCS, acWorld, False) returns PickedPoint1 converted from acUCS to acWorld

So,

PickedPoint1 = ThisDrawing.Utility.TranslateCoordinates(PickedPoint1, acUCS, acWorld, False)

would change PickedPoint1 from acUCS back to acWorld.

This would be true in this example only if you executed those functions one right after the other because a point you get from a VBA method, as implied by the variable named used here "PickedPoint1", probably only comes as a WCS point. (Just like what you found. "when i get data through acdbentity, returned coordinate are in wcs" ) Therefore to try to convert it as if it were a UCS point would result in some odd coordinate. Thus is the hard part part in keeping one's mind straight.

Plus, considering I might have the argument order backwards, you need to read the AutoCAD VBA help on this one.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost