TheSwamp

Code Red => VB(A) => Topic started by: Dommy2Hotty on November 15, 2005, 10:59:14 AM

Title: PlotOrigin Toggle
Post by: Dommy2Hotty on November 15, 2005, 10:59:14 AM
So I'm starting to dabble with VB in AutoCAD.  Managed to modify some code to get the following that will center a layout.  Also made one to set the offset back.  I can't, however, figure out how to make it toggle with one button.  I'm assuming it's the = Not part that I need to modify, but I just don't know how to.  Once again, I'm too busy to read up on it right now, so I would appreciate any suggestions on how to make it toggle, criticism about the layout, or a general explanation about how you're feeling today.  Thank you for your time.  I love you all  :love:
Code: [Select]
Sub PlotCentered()

    Dim ACADLayout As ACADLayout
   
    Set ACADLayout = ThisDrawing.ActiveLayout

    ACADLayout.CenterPlot = Not ACADLayout.CenterPlot

    ThisDrawing.Regen acAllViewports
End Sub

Sub PlotOffset()

    Dim ACADLayout As ACADLayout
    Dim newValue(0 To 1) As Double
   
    Set ACADLayout = ThisDrawing.ActiveLayout

    newValue(0) = 0
    newValue(1) = 64.516
    ACADLayout.PlotOrigin = newValue

    ThisDrawing.Regen acAllViewports
End Sub
Title: Re: PlotOrigin Toggle
Post by: deegeecees on November 15, 2005, 11:05:52 AM
Boolean comes to mind.

How bout an "IF" statement.

Pseudo Code:

If that

Then this

Else this

End If
Title: Re: PlotOrigin Toggle
Post by: Bob Wahr on November 15, 2005, 11:10:03 AM
yeah, that's what I was thinking.  Something like
Code: [Select]
Sub PlotCenteredOrNot()

    Dim objLayout As ACADLayout
   
    Set objLayout = ThisDrawing.ActiveLayout

    If objLayout.CenterPlot = False Then
        objLayout.CenterPlot = True
    Else
        newValue(0) = 0
        newValue(1) = 64.516
        objLayout.PlotOrigin = newValue
    End If
    ThisDrawing.Regen acAllViewports
End Sub

Is that what you're after?

OK, now for the criticism, or at least the critique, okay a well meant pointer.  NEVER EVER FOR ANY REASON EVER should you dim something naming it the same as it's type.  Really, don't.
Title: Re: PlotOrigin Toggle
Post by: Arizona on November 15, 2005, 11:20:19 AM
Bob,

You took the words right out of my mouth. However, Autodesk in their example does exactly the same thing. I was amazed!
Also you are right on with your statements.
Title: Re: PlotOrigin Toggle
Post by: Dommy2Hotty on November 15, 2005, 11:26:16 AM
Thank you very much everyone.  I will test out the new code at lunch time.  And yes, this code was from the help file.  Shame, shame AutoDesk!  :pissed:

Again, I'm JUST getting into this, so bear with me!
Title: Re: PlotOrigin Toggle
Post by: Dommy2Hotty on November 15, 2005, 11:36:15 AM
Error message  :cry:

(http://home.comcast.net/~dominic.cesare/pictures/AutoCAD_PlotOriginToggle_Error.jpg)
Title: Re: PlotOrigin Toggle
Post by: Bob Wahr on November 15, 2005, 11:41:17 AM
doh!  Just add "Dim newValue(0 to 1) as double" in your declarations section.
Title: Re: PlotOrigin Toggle
Post by: Dommy2Hotty on November 15, 2005, 11:50:55 AM
SUCCESS!!!   8-)
Thank you everyone!!!

Code: [Select]
Sub PlotOriginToggle()

    Dim objLayout As ACADLayout
    Dim newValue(0 To 1) As Double
   
    Set objLayout = ThisDrawing.ActiveLayout

    If objLayout.CenterPlot = False Then
        objLayout.CenterPlot = True
    Else
        newValue(0) = 0
        newValue(1) = 64.516
        objLayout.PlotOrigin = newValue
    End If
    ThisDrawing.Regen acAllViewports
End Sub
Title: Re: PlotOrigin Toggle
Post by: deegeecees on November 15, 2005, 11:52:00 AM
Glad I could help. When you making it out to Frankfort Dom?
Title: Re: PlotOrigin Toggle
Post by: Dommy2Hotty on November 15, 2005, 11:58:40 AM
Glad I could help. When you making it out to Frankfort Dom?

I was out that way last night.  My girlfriend lives in Mokena.  My ex-girlfriend (before current) lives in Frankfort, and the one before her lives in Mokena...I must like 'em from that area!
Title: Re: PlotOrigin Toggle
Post by: deegeecees on November 15, 2005, 12:03:18 PM
It is kinda backwoods out there, maybe there's something in the water.
Title: Re: PlotOrigin Toggle
Post by: Dommy2Hotty on November 15, 2005, 12:10:09 PM
It is kinda backwoods out there, maybe there's something in the water.

I know what you mean...

You probably know Morgan's & Thunderbowl...Used to manage the bowling alley and DJ in the bar...
Title: Re: PlotOrigin Toggle
Post by: deegeecees on November 15, 2005, 12:16:15 PM
Very nice pool tables there, good atmosphere, but haven't been there in a couple years. Maybe this W/E get out there and school ya in some pool.
Title: Re: PlotOrigin Toggle
Post by: Dommy2Hotty on November 15, 2005, 12:26:01 PM
Very nice pool tables there, good atmosphere, but haven't been there in a couple years. Maybe this W/E get out there and school ya in some pool.

That's a possibility...but I must warn you...my dad owns a pool hall in Crestwood...
(http://home.comcast.net/~dominic.cesare/pictures/Pockets_tables.JPG)
Title: Re: PlotOrigin Toggle
Post by: deegeecees on November 15, 2005, 12:31:35 PM
Really? A good friend of mine just sold his, "Fast Break" billiards, in Crestwood. Hmmm, interesting.
Title: Re: PlotOrigin Toggle
Post by: Dommy2Hotty on November 15, 2005, 12:59:10 PM
Really? A good friend of mine just sold his, "Fast Break" billiards, in Crestwood. Hmmm, interesting.

Yes...I do know of Fast Break...