AutoCAD Architecture Customization
Welcome to Autodesk’s AutoCAD Architecture Customization Forums. Share your knowledge, ask questions, and explore popular AutoCAD Architecture Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VB.Net code introducing instability

1 REPLY 1
Reply
Message 1 of 2
ejdavis
419 Views, 1 Reply

VB.Net code introducing instability

I've written some code to copy wall plan modifiers between walls.  The code work but introduces instability that causes an Unhandled Access Violation later in the session (closing AutoCAD always causes it).  The altered file can be openned without issue after.  How can I prevent the instability?

 

<CommandMethod("PaintWallPlanMods")> _

PublicSharedSub PaintWallPlanModifiers()

Dim objDB As Database = HostApplicationServices.WorkingDatabase

Dim objEd As Editor= DocumentManager.MdiActiveDocument.Editor

Dim strResults As String = ""

Using trans As Transaction= objDB.TransactionManager.StartTransaction

Try

Dim objSource As Wall = Nothing

Do

Dim peoSource As New PromptEntityOptions(vbCrLf & "Select source wall:")

peoSource.SetRejectMessage(vbCrLf & "Invalid selection.")

peoSource.AddAllowedClass(GetType(Wall), True)

Dim perSource As PromptEntityResult= objEd.GetEntity(peoSource)

If perSource.Status = PromptStatus.Cancel Then strResults = " Canceled at Source Selection." : Exit Try

objSource = perSource.ObjectId.GetObject(OpenMode.ForRead)

If objSource.WallModifierCount > 0 Then Exit Do

Loop

Dim peoTarget As New PromptEntityOptions(vbCrLf & "Select target wall:")

peoTarget.SetRejectMessage(vbCrLf & "Invalid selection.")

peoTarget.AddAllowedClass(GetType(Wall), True)

Dim perTarget As PromptEntityResult= objEd.GetEntity(peoTarget)

If perTarget.Status = PromptStatus.Cancel Then strResults = " Canceled at Target Selection." : Exit Try

Dim objTarget As Wall = perTarget.ObjectId.GetObject(OpenMode.ForRead) 

If objTarget.WallModifierCount > 0 Then strResults = " Wall already has modifiers." : Exit Try

objTarget.UpgradeOpen()

For Each objMod As WallModifier In objSource.WallModifiers

objTarget.WallModifiers.Add(objMod)

Next

Catch

End Try

trans.Commit()

objEd.WriteMessage(vbCrLf & strResults & vbCrLf)

End Using

End Sub

1 REPLY 1
Message 2 of 2
Gary_J_Orr
in reply to: ejdavis

Something is "still open" and trying to do it's thing... Try manually closing your transaction after your "End Using":
trans.Dispose()
Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)

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

Post to forums  

Autodesk Design & Make Report

”Boost