.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Save and Restore UCS

8 REPLIES 8
Reply
Message 1 of 9
dlhartley
3365 Views, 8 Replies

Save and Restore UCS

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 toSmiley Sad

Thanks,

David

 

8 REPLIES 8
Message 2 of 9
matus.brlit
in reply to: dlhartley

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

Message 3 of 9
dlhartley
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.

Message 4 of 9

You can P/Invoke acedSetCurrentUCS, acedGetCurrentUCS and acedRestorePreviousUCS

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 5 of 9
dlhartley
in reply to: dlhartley

Thanks!  That sounds like a better approach

Message 6 of 9
dlhartley
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

Message 7 of 9
junoj
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,

 

 

 

Message 8 of 9
jeff
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
Message 9 of 9
junoj
in reply to: jeff

Thank you very much Jeff !!!!    Smiley Happy 

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost