Valued Contributor
Posts: 54
Registered: ‎11-12-2012
Message 1 of 6 (197 Views)
Accepted Solution

unwanted zoom in loop command

197 Views, 5 Replies
02-12-2013 06:02 AM

I have a portion of my routine below. Basically I need the user to continue to loop through the command. They are picking Circles or blocks in the drawing and I get the insertion point, then insert a new block. However, whenever they try and use a transparent zoom or pan to move around the drawing when the promptentityresult is hit, it zooms back to the original location. How do I stop it from doing that? Any help or direction is much appreciated. Here is a code....


CommandMethod("getpnt", CommandFlags.Session)> _

  Sub findpnt()

  Dim cnt AsInteger = 0

  Dim NEWPNT AsPoint3d = GetInsPoint()

  While cnt < 3

            NEWPNT = GetInsPoint()

' other code is inserted here...

            cnt = cnt + 1



Public Function GetInsPoint()      

Dim inspnt AsPoint3d      

Dim acdoced AsDocument = Application.DocumentManager.MdiActiveDocument       

Dim myed AsEditor = acdoced.Editor       

Dim db AsDatabase = HostApplicationServices.WorkingDatabase      

Using mytrans2 AsTransaction = db.TransactionManager.StartTransaction()           

Dim myPEO AsNewPromptEntityOptions(vbLf & "Select Circle or Block: ")


"You must select a Circle or Block.")


GetType(Circle), True)


GetType(BlockReference), True)

            myPEO.AllowNone =


Dim symbolent AsPromptEntityResult = myed.GetEntity(myPEO)           

If symbolent.Status = PromptStatus.OK Then              

Dim Objid AsObjectId = symbolent.ObjectId               

Dim ent AsEntity = CType(mytrans2.GetObject(Objid, OpenMode.ForRead), Entity)             

Dim enttype1 AsString = ent.GetType().ToString               

Dim enttype AsString = Objid.ObjectClass.DxfName               

SelectCase enttype                   


Dim circleobj AsCircle = mytrans2.GetObject(Objid, OpenMode.ForRead)

                        inspnt = circleobj.Center                   


Dim blockent AsBlockReference = mytrans2.GetObject(Objid, OpenMode.ForRead)

inspnt = blockent.Position               




Return inspnt   



*Expert Elite*
Posts: 987
Registered: ‎04-27-2009
Message 2 of 6 (185 Views)

Re: unwanted zoom in loop command

02-12-2013 08:12 AM in reply to: cjacobi

This is an interesting issue I have not noticed before and did not know current view seems associated with a new started transaction.


The reason AutoCAD always restore back to original view after each pick is that you did not commit the Transaction in the GetInsPoint() function.


As rule of thumb, one should always EXPLICITLY complete the transaction, either commit it, or abort it. If a transaction is wrapped in Using ... End Using, when End Using is reached, if the transaction has not been commited, it will be aborted before being disposed, which may not be what you want, as your code behaves.


So, you need to add mytrans2.Commit() right before End Using.


Valued Contributor
Posts: 54
Registered: ‎11-12-2012
Message 3 of 6 (186 Views)

Re: unwanted zoom in loop command

02-12-2013 08:15 AM in reply to: norman.yuan

thanks!  I will make that change. maybe that will resolve the issue.

*Expert Elite*
Posts: 987
Registered: ‎04-27-2009
Message 4 of 6 (182 Views)

Re: unwanted zoom in loop command

02-12-2013 08:18 AM in reply to: cjacobi

I forgot to mention: I actually tried your code.


Not "maybe". It IS because of the transaction not being commited.

Valued Contributor
Posts: 54
Registered: ‎11-12-2012
Message 5 of 6 (182 Views)

Re: unwanted zoom in loop command

02-12-2013 08:25 AM in reply to: cjacobi

That was it.....found a couple other locations that I did not commit my transactions. Still learning .NET as you can tell.


Once I got those cleared up, the routine is working like it should and is not zooming automatically!


Thanks so much for your help.

Posts: 1,406
Registered: ‎04-09-2008
Message 6 of 6 (167 Views)

Re: unwanted zoom in loop command

02-12-2013 12:26 PM in reply to: norman.yuan

Excellent, Norman!

I thought that this is due to CommandFlags.Session, but you're absolutely right.

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

Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

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