Author Topic: Total newby to the swamp... VB block insertion  (Read 33785 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Re: Total newby to the swamp... VB block insertion
« Reply #105 on: May 26, 2006, 03:25:17 PM »
would it be done with an array?  Thinking about it, that would be a pretty easy way to handle it.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

Bob Wahr

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #106 on: May 26, 2006, 04:22:59 PM »
My mistake, it was Mark who did it.  His username was simply Mark and I don't remember his last name.  If anyone else does, please post it so he gets the credit.
Code: [Select]
Option Explicit
' Setting saver is to ensure that users have their current settings saved
' and restored when custom VBA programs are done.

Private iOSMode As Integer ' Sets the object snap mode
Private iOrthoMode As Integer ' Turns ortho mode on or off
Private iSnapMode As Integer ' Turns snap on or off
Private iAttDia As Integer ' Controls whether a dialog is shown for attribute values
Private iAUnits As Integer ' Sets units for angles
Private iBlipMode As Integer ' Turns blips on or off
Private sCEColor As String 'Sets the color of new objects
Private dCELTScale As Double 'Sets the current object linetype scaling factor
Private sCELType As String 'Sets the linetype of new objects
Private dChamferA As Double 'Sets the first chamfer distance
Private dChamferB As Double 'Sets the second chamfer distance
Private dChamferC As Double ' Sets the chamfer length
Private dChamferD As Double ' Sets the chamfer angle
Private sCLayer As String ' Sets the current layer
Private iCMDEcho As Integer ' Controls whether AutoCAD echoes prompts and input during the AutoLISP (command) function
Private iEdgeMode As Integer ' Controls how TRIM and EXTEND determine cutting and boundary edges
Private iFileDia As Integer ' Suppresses display of the file dialog boxes
Private iGridMode As Integer ' Specifies whether the grid is turned on or off
Private iHighlight As Integer ' Controls object highlighting; does not affect objects selected with grips
Private dLTScale As Double ' Sets the global linetype scale factor
Private iLUnits As Integer ' Sets linear units
Private iLUPrec As Integer ' Sets the number of decimal places displayed for linear units
Private iMenuEcho As Integer ' Sets menu echo and prompt control bits
Private iMirrText As Integer ' Controls how MIRROR reflects text
Private iPDMode As Integer ' Controls how point objects are displayed
Private iPDSize As Double ' Sets the display size for point objects
Private iProjMode As Integer ' Sets the current Projection mode for trimming or extending
Private dSnapAng As Double ' Sets snap and grid rotation angle for the current viewport
Private vSnapBase As Variant ' Sets the snap and grid origin point for the current viewport relative to the current UCS
Private iSnapISOPair As Integer ' Controls the isometric plane for the current viewport
Private iSnapStyl As Integer ' Sets snap style for the current viewport
Private vSnapUnit As Variant ' Sets the snap spacing for the current viewport
Private iUCSIcon As Integer ' Displays the UCS icon for the current viewport
Private iUnitMode As Integer ' Controls the display format for units

Private Sub SaveCADSettings()

iOSMode = ThisDrawing.GetVariable("OSMODE")
iOrthoMode = ThisDrawing.GetVariable("ORTHOMODE")
iSnapMode = ThisDrawing.GetVariable("SNAPMODE")
iAttDia = ThisDrawing.GetVariable("ATTDIA")
iAUnits = ThisDrawing.GetVariable("AUNITS")
iBlipMode = ThisDrawing.GetVariable("BLIPMODE")
sCEColor = ThisDrawing.GetVariable("CECOLOR")
dCELTScale = ThisDrawing.GetVariable("CELTSCALE")
sCELType = ThisDrawing.GetVariable("CELTYPE")
dChamferA = ThisDrawing.GetVariable("CHAMFERA")
dChamferB = ThisDrawing.GetVariable("CHAMFERB")
dChamferC = ThisDrawing.GetVariable("CHAMFERC")
dChamferD = ThisDrawing.GetVariable("CHAMFERD")
sCLayer = ThisDrawing.GetVariable("CLAYER")
iCMDEcho = ThisDrawing.GetVariable("CMDECHO")
iEdgeMode = ThisDrawing.GetVariable("EDGEMODE")
iFileDia = ThisDrawing.GetVariable("FILEDIA")
iGridMode = ThisDrawing.GetVariable("GRIDMODE")
iHighlight = ThisDrawing.GetVariable("HIGHLIGHT")
dLTScale = ThisDrawing.GetVariable("LTSCALE")
iLUnits = ThisDrawing.GetVariable("LUNITS")
iLUPrec = ThisDrawing.GetVariable("LUPREC")
iMenuEcho = ThisDrawing.GetVariable("MENUECHO")
iMirrText = ThisDrawing.GetVariable("MIRRTEXT")
iPDMode = ThisDrawing.GetVariable("PDMODE")
iPDSize = ThisDrawing.GetVariable("PDSIZE")
iProjMode = ThisDrawing.GetVariable("PROJMODE")
dSnapAng = ThisDrawing.GetVariable("SNAPANG")
vSnapBase = ThisDrawing.GetVariable("SNAPBASE")
iSnapISOPair = ThisDrawing.GetVariable("SNAPISOPAIR")
iSnapStyl = ThisDrawing.GetVariable("SNAPSTYL")
vSnapUnit = ThisDrawing.GetVariable("SNAPUNIT")
iUCSIcon = ThisDrawing.GetVariable("UCSICON")
iUnitMode = ThisDrawing.GetVariable("UNITMODE")

End Sub

Private Sub RecallCADSettings()
ThisDrawing.SetVariable "OSMODE", iOSMode
ThisDrawing.SetVariable "ORTHOMODE", iOrthoMode
ThisDrawing.SetVariable "SNAPMODE", iSnapMode
ThisDrawing.SetVariable "ATTDIA", iAttDia
ThisDrawing.SetVariable "AUNITS", iAUnits
ThisDrawing.SetVariable "BLIPMODE", iBlipMode
ThisDrawing.SetVariable "CECOLOR", sCEColor
ThisDrawing.SetVariable "CELTSCALE", dCELTScale
ThisDrawing.SetVariable "CELTYPE", sCELType
ThisDrawing.SetVariable "CHAMFERA", dChamferA
ThisDrawing.SetVariable "CHAMFERB", dChamferB
ThisDrawing.SetVariable "CHAMFERC", dChamferC
ThisDrawing.SetVariable "CHAMFERD", dChamferD
ThisDrawing.SetVariable "CLAYER", sCLayer
ThisDrawing.SetVariable "CMDECHO", iCMDEcho
ThisDrawing.SetVariable "EDGEMODE", iEdgeMode
ThisDrawing.SetVariable "FILEDIA", iFileDia
ThisDrawing.SetVariable "GRIDMODE", iGridMode
ThisDrawing.SetVariable "HIGHLIGHT", iHighlight
ThisDrawing.SetVariable "LTSCALE", dLTScale
ThisDrawing.SetVariable "LUNITS", iLUnits
ThisDrawing.SetVariable "LUPREC", iLUPrec
ThisDrawing.SetVariable "MENUECHO", iMenuEcho
ThisDrawing.SetVariable "MIRRTEXT", iMirrText
ThisDrawing.SetVariable "PDMODE", iPDMode
ThisDrawing.SetVariable "PDSIZE", iPDSize
ThisDrawing.SetVariable "PROJMODE", iProjMode
ThisDrawing.SetVariable "SNAPANG", dSnapAng
ThisDrawing.SetVariable "SNAPBASE", vSnapBase
ThisDrawing.SetVariable "SNAPISOPAIR", iSnapISOPair
ThisDrawing.SetVariable "SNAPSTYL", iSnapStyl
ThisDrawing.SetVariable "SNAPUNIT", vSnapUnit
ThisDrawing.SetVariable "UCSICON", iUCSIcon
ThisDrawing.SetVariable "UNITMODE", iUnitMode

End Sub

Private Sub Class_Initialize()
Call SaveCADSettings
End Sub

Private Sub Class_Terminate()
Call RecallCADSettings
End Sub

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Re: Total newby to the swamp... VB block insertion
« Reply #107 on: May 26, 2006, 05:17:34 PM »
ok, I understand most  of that.  Why the Class_Init and Terminate at the bottom?
Why not just Call SaveCADSettings from your routine?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Re: Total newby to the swamp... VB block insertion
« Reply #108 on: May 26, 2006, 05:19:06 PM »
And was it a class module or just a module?
« Last Edit: May 30, 2006, 10:34:24 AM by CmdrDuh »
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

Bob Wahr

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #109 on: May 26, 2006, 05:30:13 PM »
I believe it's to automate it.  You initialize the class everything gets saved.  You terminate the class, everything gets unsaved.  This was saved out in my "bunch o' crap that looks like it will be hella usefull" folder.  I'll have to go through my ECC archive when I get to the house for more clarity on the matter.


****

Class module

Bryco

  • Water Moccasin
  • Posts: 1864
Re: Total newby to the swamp... VB block insertion
« Reply #110 on: May 26, 2006, 05:42:44 PM »
Mark Johnston.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Re: Total newby to the swamp... VB block insertion
« Reply #111 on: May 26, 2006, 05:50:31 PM »
not to ask stupid questions, but is Class_Initialize() a autocad builtin function or do you just run it like any other sub?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

Bob Wahr

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #112 on: May 26, 2006, 05:58:01 PM »
Thanks Bryco

Duh, when you initialize the class it would go.  Much like Userform_Initialize

Jeff_M

  • King Gator
  • Posts: 4042
  • C3D user & customizer
Re: Total newby to the swamp... VB block insertion
« Reply #113 on: May 26, 2006, 09:07:51 PM »
cmdrDuh,
Place the code Bob posted in a Class module, name the Class via the Properties window to MyVars, then add a Standard Module with this code and step through it to see how it works.

Code: [Select]
Sub test()
Dim cMyvars As MyVars

Set cMyvars = New MyVars

''do whatever

Set cMyvars = Nothing
End Sub

ScottBolton

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #114 on: June 14, 2006, 03:45:44 PM »
I AM EXHAUSTED! Jeff pointed me here from discussion.autodesk and I've spent the whole day reading the thread. I think the only word I understood was "trout".  :cry:

Anyhoo I'll retrack and hopefully be considerably better at VBA at the end of it.

Regarding images, I found this trick on msdn.microsoft and it involves creating a library userform with lots of images on it. Then just change your preview image by referencing your library:

Preview.Picture = bTLibrary.Diag1003_4.Picture

Works a treat and no DLL in sight.

S

Bob Wahr

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #115 on: June 14, 2006, 03:49:15 PM »
Scott, welcome to the fray.  Take small bites, it's easier to digest that way.  Ask all the questions that you want and/or need to.

ScottBolton

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #116 on: June 14, 2006, 03:52:34 PM »
Bob, this thread is already waaaaay too long for me to ask ALL the questions I want!

I am confident that I've found a new home though. Thanks for the welcome.

I'll be in touch - that you can count on!

S

Bob Wahr

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #117 on: June 14, 2006, 04:01:08 PM »
Bob, this thread is already waaaaay too long for me to ask ALL the questions I want!
Start new ones, lots of them.  How much experience with VBA do you have?  I ask because if you are a beginner, CmdrDuh has a VBA class going.  It's currently on hiatus and if I remember our last conversation correctly, about to be revamped but you might want to shoot him a PM and talk to him about it.

ScottBolton

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #118 on: June 14, 2006, 04:19:40 PM »
Bob, I have trouble spelling BVA - does that answer your question? Seriously I haven't a Scooby. Although all of my Lisp routines now adopt VBA for the GUI (isn't DCL clunky?) everything is passed to a tmp file then read back into Lisp where I'm as happy as Larry. I have yet to actually do something in VBA. All the Dims and the Privates leave me cold. I have two books that prop up my desk to just the right height. CD's class sounds good and I've sent a PM. Thanks for the tip.

S

Jeff_M

  • King Gator
  • Posts: 4042
  • C3D user & customizer
Re: Total newby to the swamp... VB block insertion
« Reply #119 on: June 14, 2006, 05:07:28 PM »
Hi Scott,
I'm glad you found your way over here. As Bob said, don't be afraid to ask questions of any type. IIRC this thread was started due to it being akdrafter's first attempt at a VBA program. I know that he, too, came from a lisp background, so it CAN  be done.....heck, I came from lisp into VBA, also, and now I'm venturing out into the .NET world......

Anyway, welcome to theSwamp and make yourself at home.