.NET

Reply
Distinguished Contributor
dlhartley
Posts: 120
Registered: ‎01-13-2009
Message 1 of 9 (1,517 Views)

Save and Restore UCS

1517 Views, 8 Replies
03-08-2011 12:23 PM

I'm fairly new to this, but I'm confused looking through the vb.net developer's guide and online for information about transforming the UCS.

I'd like to:

1:  Save the user's current UCS,

2:  Change to the World UCS (that's easy)

2:  Do things

3: Set the UCS back to the user's original UCS

 

Is there no simple way to do this?

If not I may have to learn more about matrix operations than I really wanted to:smileysad:

Thanks,

David

 

Mentor
matus.brlit
Posts: 246
Registered: ‎03-11-2008
Message 2 of 9 (1,495 Views)

Re: Save and Restore UCS

03-09-2011 03:20 AM in reply to: dlhartley

UCS only affects user interaction, all your operations with entities take place in WCS

Distinguished Contributor
dlhartley
Posts: 120
Registered: ‎01-13-2009
Message 3 of 9 (1,490 Views)

Re: Save and Restore UCS

03-09-2011 06:48 AM in reply to: dlhartley

Part of what I'm doing involves extrusions, and I get unpredictable results if I don't first set the UCS to world.

In VBA this was fairly straightforward, but different in vb.net, hence the posting.

Moderator
Alexander.Rivilis
Posts: 1,417
Registered: ‎04-09-2008
Message 4 of 9 (1,484 Views)

Re: Save and Restore UCS

03-09-2011 07:25 AM in reply to: dlhartley

You can P/Invoke acedSetCurrentUCS, acedGetCurrentUCS and acedRestorePreviousUCS


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Distinguished Contributor
dlhartley
Posts: 120
Registered: ‎01-13-2009
Message 5 of 9 (1,468 Views)

Re: Save and Restore UCS

03-09-2011 11:04 AM in reply to: dlhartley

Thanks!  That sounds like a better approach

Distinguished Contributor
dlhartley
Posts: 120
Registered: ‎01-13-2009
Message 6 of 9 (1,442 Views)

Re: Save and Restore UCS

03-10-2011 07:04 AM in reply to: dlhartley

After doing some research, part of my problem was not knowing what I was looking for.  The following code does what I need, except for one thing:

The viewport changes to the orthogonal plan view at the end of the toUser Sub.

How do I keep the user's viewport view as-is?

 

Thanks,

David

 

Public vect1 As Vector3d

Public vect2 As Vector3d

Public org As Point3d

 

 

 Public Sub toWorld()

            Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument

            Dim acCurDb As Database = acDoc.Database

            vect1 = acCurDb.Ucsxdir

            vect2 = acCurDb.Ucsydir

            org = acCurDb.Ucsorg

            acDoc.Editor.CurrentUserCoordinateSystem = Matrix3d.Identity

        End Sub  

 

 

Public Sub restoreUCS()

 

            Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument

            Dim acCurDb As Database = acDoc.Database

            Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

                '' Open the UCS table for read

                Dim acUCSTbl As UcsTable

                acUCSTbl = acTrans.GetObject(acCurDb.UcsTableId, OpenMode.ForRead)

 

                Dim acUCSTblRec As UcsTableRecord

                If acUCSTbl.Has("New_UCS") = False Then

                    acUCSTblRec = New UcsTableRecord()

                    acUCSTblRec.Name = "New_UCS"

                    acUCSTbl.UpgradeOpen()

 

                    acUCSTbl.Add(acUCSTblRec)

 

                    acTrans.AddNewlyCreatedDBObject(acUCSTblRec, True)

                Else

                    acUCSTblRec = acTrans.GetObject(acUCSTbl("New_UCS"), OpenMode.ForWrite)

                End If

 

                acUCSTblRec.Origin = org

                acUCSTblRec.XAxis = vect1

                acUCSTblRec.YAxis = vect2

 

                '' Open the active viewport

 

                Dim acVportTblRec As ViewportTableRecord

 

                '' Set the UCS current

                acVportTblRec.SetUcs(acUCSTblRec.ObjectId)

                acDoc.Editor.UpdateTiledViewportsFromDatabase()

 

                acTrans.Commit()

 

            End Using

End Sub

Distinguished Contributor
junoj
Posts: 116
Registered: ‎02-26-2009
Message 7 of 9 (650 Views)

Re: Save and Restore UCS

06-20-2013 08:36 AM in reply to: dlhartley

Hi David, I am trying to do the same thing you are trying to do. I would like to change the UCS then create a polyline on a new UCS (not same as WCS). But when I create a polyline it adds it using WCS. Can you please point me to the right direction.

 

Thank you,

 

 

 

Valued Mentor
jeff
Posts: 330
Registered: ‎05-12-2009
Message 8 of 9 (639 Views)

Re: Save and Restore UCS

06-20-2013 10:24 AM in reply to: junoj

See this article about using Editor.CurrentUserCoordinateSystem Property

http://spiderinnet1.typepad.com/blog/2012/03/autocad-net-api-ucswcs-entity-creation-and-matrix3dtran...

You can also find your answers @ TheSwamp
Distinguished Contributor
junoj
Posts: 116
Registered: ‎02-26-2009
Message 9 of 9 (632 Views)

Re: Save and Restore UCS

06-20-2013 12:57 PM in reply to: jeff

Thank you very much Jeff !!!!    :smileyhappy: 

Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.