TheSwamp

Code Red => VB(A) => Topic started by: Matersammichman on July 26, 2006, 09:36:53 AM

Title: Setting an existing Door Style
Post by: Matersammichman on July 26, 2006, 09:36:53 AM
Anyone have a simple blurb to set a predefined Door Style as current?
Title: Re: Setting an existing Door Style
Post by: BAshworth on July 26, 2006, 12:00:31 PM
It's either a setting in the Windows registry, or some xData hoo ha, I don't remember which off the top of my head.. trust me, SendCommand is your best bet here.

*** Added ***

It's in the registry.. here's the key.. on mine at least.  your mileage may vary depending on which version you use.

HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R16.0\ACAD-204:409\Profiles\<current profile name>\Dialogs\AecArchX40-DoorAdd\StyleName

By the way, this is the same general location and method for setting ANY object style as current.  Walls, doors, windows, etc...
Title: Re: Setting an existing Door Style
Post by: Matersammichman on July 26, 2006, 01:11:17 PM
??? :-o
I don't want to create a new door style, I want to set an existing style as current through vba.
Title: Re: Setting an existing Door Style
Post by: Bob Wahr on July 26, 2006, 03:00:50 PM
He's told you where the info needs to be set and suggested that you use send command instead.  He doesn't say anything about creating a new style.
Title: Re: Setting an existing Door Style
Post by: Matersammichman on July 26, 2006, 03:03:21 PM
I have to change Registry Settings to change the active Door Style?
Title: Re: Setting an existing Door Style
Post by: Bob Wahr on July 26, 2006, 03:06:56 PM
Not having ADT myself, I can't say for sure but based on my knowledge of BAshworth's knowledge, yes unless you use send command.  I have heard that what ADT exposes to VBA is limited and pathetic.  Looks like this is an example of it.
Title: Re: Setting an existing Door Style
Post by: Matersammichman on July 26, 2006, 03:08:50 PM
(Whew!!!) Man, no joke. That's tough work for a simple change manually!
Title: Re: Setting an existing Door Style
Post by: DaveW on July 26, 2006, 03:48:49 PM
These guys made a good suggestion to you.

Do you know what, SendCommabd", is?

If not. look it up and your issue is solved.

thisdrawing.sendcommand "blah" & vbcr
Title: Re: Setting an existing Door Style
Post by: Matersammichman on July 26, 2006, 03:53:25 PM
Yes, I know what "Send Command" is, and I'm not trying to be rude, but the truth is, using "send command" to perform this function flawlessly is not as simple as you might think for this. Try to make it work yourself before you judge my abiities.
Title: Re: Setting an existing Door Style
Post by: DaveW on July 26, 2006, 07:38:27 PM
Sorry,

Not trying to be rude either. Quick comments have a tendency to be misread.

I use sendcommand all the time. I deal with 3D solids mostly. As a result, many methods are not available, such as align. I also use it to run pedit and setting the ucs. I realize it can be tricky to use at different prompts and sometimes will not work at all, such as making a grouped set selectable, because the prompt has to be read and then replied to.

In your case an advanced programmer that appears to understand quite a bit of exactly what you are trying to do recommends it. I know, sometimes it is frustrating, and sendcommand is no exception.

Your other choice is the registry. It is not an issue to write to that either.
You are just going to have to make a choice and get it done. :)

The code below will do quite a bit with the reg. You will need to add your own code to call the functions you will need. Put the code in a module, not a form and just call the functions and pass them the strings.

Good luck,

Dave

Code: [Select]
' Created by E.Spencer (elliot@spnc.demon.co.uk) - This code is public domain.
'
Option Explicit
Global sValue As String
'Security Mask constants
Public Const READ_CONTROL = &H20000
Public Const SYNCHRONIZE = &H100000
Public Const STANDARD_RIGHTS_ALL = &H1F0000
Public Const STANDARD_RIGHTS_READ = READ_CONTROL
Public Const STANDARD_RIGHTS_WRITE = READ_CONTROL
Public Const KEY_QUERY_VALUE = &H1
Public Const KEY_SET_VALUE = &H2
Public Const KEY_CREATE_SUB_KEY = &H4
Public Const KEY_ENUMERATE_SUB_KEYS = &H8
Public Const KEY_NOTIFY = &H10
Public Const KEY_CREATE_LINK = &H20
Public Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or _
   KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or _
   KEY_CREATE_LINK) And (Not SYNCHRONIZE))
Public Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or _
   KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
Public Const KEY_EXECUTE = ((KEY_READ) And (Not SYNCHRONIZE))
Public Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE _
   Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
' Possible registry data types
Public Enum InTypes
   ValNull = 0
   ValString = 1
   ValXString = 2
   ValBinary = 3
   ValDWord = 4
   ValLink = 6
   ValMultiString = 7
   ValResList = 8
End Enum

Public Type typSrings
  Val1 As String
  Val2 As String
End Type



' Registry value type definitions
Public Const REG_NONE As Long = 0
Public Const REG_SZ As Long = 1
Public Const REG_EXPAND_SZ As Long = 2
Public Const REG_BINARY As Long = 3
Public Const REG_DWORD As Long = 4
Public Const REG_LINK As Long = 6
Public Const REG_MULTI_SZ As Long = 7
Public Const REG_RESOURCE_LIST As Long = 8
' Registry section definitions
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const HKEY_CURRENT_CONFIG = &H80000005
Public Const HKEY_DYN_DATA = &H80000006
' Codes returned by Reg API calls
Private Const ERROR_NONE = 0
Private Const ERROR_BADDB = 1
Private Const ERROR_BADKEY = 2
Private Const ERROR_CANTOPEN = 3
Private Const ERROR_CANTREAD = 4
Private Const ERROR_CANTWRITE = 5
Private Const ERROR_OUTOFMEMORY = 6
Private Const ERROR_INVALID_PARAMETER = 7
Private Const ERROR_ACCESS_DENIED = 8
Private Const ERROR_INVALID_PARAMETERS = 87
Private Const ERROR_NO_MORE_ITEMS = 259
' Registry API functions used in this module (there are more of them)
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As Long
Private Declare Function RegSetValueExLong Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, ByVal cbData As Long) As Long
Private Declare Function RegFlushKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long

' This routine allows you to get values from anywhere in the Registry, it currently
' only handles string, double word and binary values. Binary values are returned as
' hex strings.
'
' Example
' Text1.Text = ReadRegistry(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultUserName")
'
Public Function ReadRegistry(ByVal Group As Long, ByVal Section As String, ByVal Key As String) As String
Dim lResult As Long, lKeyValue As Long, lDataTypeValue As Long, lValueLength As Long, sValue As String, td As Double
Dim TStr1 As String, TStr2 As String
Dim i As Integer
On Error Resume Next
lResult = RegOpenKey(Group, Section, lKeyValue)
sValue = Space$(2048)
lValueLength = Len(sValue)
lResult = RegQueryValueEx(lKeyValue, Key, 0&, lDataTypeValue, sValue, lValueLength)
If (lResult = 0) And (Err.Number = 0) Then
   If lDataTypeValue = REG_DWORD Then
      td = Asc(Mid$(sValue, 1, 1)) + &H100& * Asc(Mid$(sValue, 2, 1)) + &H10000 * Asc(Mid$(sValue, 3, 1)) + &H1000000 * CDbl(Asc(Mid$(sValue, 4, 1)))
      sValue = Format$(td, "000")
   End If
   If lDataTypeValue = REG_BINARY Then
       ' Return a binary field as a hex string (2 chars per byte)
       TStr2 = ""
       For i = 1 To lValueLength
          TStr1 = Hex(Asc(Mid(sValue, i, 1)))
          If Len(TStr1) = 1 Then TStr1 = "0" & TStr1
          TStr2 = TStr2 + TStr1
       Next
       sValue = TStr2
   Else
      sValue = Left$(sValue, lValueLength - 1)
   End If
Else
   sValue = "Not Found"
End If
lResult = RegCloseKey(lKeyValue)
ReadRegistry = sValue
End Function

' This routine allows you to write values into the entire Registry, it currently
' only handles string and double word values.
'
' Example
' WriteRegistry HKEY_CURRENT_USER, "SOFTWARE\My Name\My App\", "NewSubKey", ValString, "NewValueHere"
' WriteRegistry HKEY_CURRENT_USER, "SOFTWARE\My Name\My App\", "NewSubKey", ValDWord, "31"
'
Public Sub WriteRegistry(ByVal Group As Long, ByVal Section As String, ByVal Key As String, ByVal ValType As InTypes, ByVal Value As Variant)
Dim lResult As Long
Dim lKeyValue As Long
Dim InLen As Long
Dim lNewVal As Long
Dim sNewVal As String
On Error Resume Next
lResult = RegCreateKey(Group, Section, lKeyValue)
If ValType = ValDWord Then
   lNewVal = CLng(Value)
   InLen = 4
   lResult = RegSetValueExLong(lKeyValue, Key, 0&, ValType, lNewVal, InLen)
Else
   ' Fixes empty string bug - spotted by Marcus Jansson
   If ValType = ValString Then Value = Value + Chr(0)
   sNewVal = Value
   InLen = Len(sNewVal)
   lResult = RegSetValueExString(lKeyValue, Key, 0&, 1&, sNewVal, InLen)
End If
lResult = RegFlushKey(lKeyValue)
lResult = RegCloseKey(lKeyValue)
End Sub

' This routine enumerates the subkeys under any given key
' Call repeatedly until "Not Found" is returned - store values in array or something
'
' Example - this example just adds all the subkeys to a string - you will probably want to
' save then into an array or something.
'
' Dim Res, NewLine As String
' Dim i As Long
' Res = ReadRegistryGetSubkey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\", i)
' NewLine = ""
' Do Until Res = "Not Found"
'   Text1.Text = Text1.Text & NewLine & Res
'   i = i + 1
'   Res = ReadRegistryGetSubkey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\", i)
'   NewLine = Chr(13) & Chr(10)
' Loop

Public Function ReadRegistryGetSubkey(ByVal Group As Long, ByVal Section As String, Idx As Long) As String
Dim lResult As Long, lKeyValue As Long, lDataTypeValue As Long, lValueLength As Long, sValue As String, td As Double
On Error Resume Next
lResult = RegOpenKey(Group, Section, lKeyValue)
sValue = Space$(2048)
lValueLength = Len(sValue)
lResult = RegEnumKey(lKeyValue, Idx, sValue, lValueLength)
If (lResult = 0) And (Err.Number = 0) Then
   sValue = Left$(sValue, InStr(sValue, Chr(0)) - 1)
Else
   sValue = "Not Found"
End If
lResult = RegCloseKey(lKeyValue)
ReadRegistryGetSubkey = sValue
End Function

' This routine allows you to get all the values from anywhere in the Registry under any
' given subkey, it currently only returns string and double word values.
'
' Example - returns list of names/values to multiline text box
' Dim Res As Variant
' Dim i As Long
' Res = ReadRegistryGetAll(HKEY_CURRENT_USER, "Software\Microsoft\Notepad", i)
' Do Until Res(2) = "Not Found"
'    Text1.Text = Text1.Text & Chr(13) & Chr(10) & Res(1) & " " & Res(2)
'    i = i + 1
'    Res = ReadRegistryGetAll(HKEY_CURRENT_USER, "Software\Microsoft\Notepad", i)
' Loop
'
Public Function ReadRegistryGetAll(ByVal Group As Long, ByVal Section As String, Idx As Long) As Variant
Dim lResult As Long, lKeyValue As Long, lDataTypeValue As Long
Dim lValueLength As Long, lValueNameLength As Long
Dim sValueName As String ', sValue As String
Dim td As Double
On Error Resume Next
lResult = RegOpenKey(Group, Section, lKeyValue)
sValue = Space$(2048)
sValueName = Space$(2048)
lValueLength = Len(sValue)
lValueNameLength = Len(sValueName)
lResult = RegEnumValue(lKeyValue, Idx, sValueName, lValueNameLength, 0&, lDataTypeValue, sValue, lValueLength)
If (lResult = 0) And (Err.Number = 0) Then
   If lDataTypeValue = REG_DWORD Then
      td = Asc(Mid$(sValue, 1, 1)) + &H100& * Asc(Mid$(sValue, 2, 1)) + &H10000 * Asc(Mid$(sValue, 3, 1)) + &H1000000 * CDbl(Asc(Mid$(sValue, 4, 1)))
      sValue = Format$(td, "000")
   End If
   sValue = Left$(sValue, lValueLength - 1)
   sValueName = Left$(sValueName, lValueNameLength)
Else
   sValue = "Not Found"
End If
lResult = RegCloseKey(lKeyValue)
' Return the datatype, value name and value as an array
ReadRegistryGetAll = Array(lDataTypeValue, sValueName, sValue)
End Function

' This routine deletes a specified key (and all its subkeys and values if on Win95) from the registry.
' Be very careful using this function.
'
' Example
' DeleteSubkey HKEY_CURRENT_USER, "Software\My Name\My App"
'
Public Function DeleteSubkey(ByVal Group As Long, ByVal Section As String) As String
Dim lResult As Long, lKeyValue As Long
On Error Resume Next
lResult = RegOpenKeyEx(Group, vbNullChar, 0&, KEY_ALL_ACCESS, lKeyValue)
lResult = RegDeleteKey(lKeyValue, Section)
lResult = RegCloseKey(lKeyValue)
End Function

' This routine deletes a specified value from below a specified subkey.
' Be very careful using this function.
'
' Example
' DeleteValue HKEY_CURRENT_USER, "Software\My Name\My App", "NewSubKey"
'
Public Function DeleteValue(ByVal Group As Long, ByVal Section As String, ByVal Key As String) As String
Dim lResult As Long, lKeyValue As Long
On Error Resume Next
lResult = RegOpenKey(Group, Section, lKeyValue)
lResult = RegDeleteValue(lKeyValue, Key)
lResult = RegCloseKey(lKeyValue)
End Function
Title: Re: Setting an existing Door Style
Post by: Bob Wahr on July 26, 2006, 08:18:57 PM
In your case an advanced programmer that appears to understand quite a bit of exactly what you are trying to do recommends it.
Don't say stuff like that.  I'm going to be hanging around with him all weekend, he doesn't need head enlargement therapy right now.
Title: Re: Setting an existing Door Style
Post by: DaveW on July 26, 2006, 10:54:55 PM
Huh?

I was taking about the guy you mentioned. I do not understand. We seem to have trouble communicating so I'll just stear clear.
Title: Re: Setting an existing Door Style
Post by: Bob Wahr on July 26, 2006, 10:58:45 PM
I was talking about him too.  I was just playing.  He and his family are visiting us this weekend.  My comment was actually directed to wim in a sideways fashion.  Sorry.
Title: Re: Setting an existing Door Style
Post by: Matersammichman on July 27, 2006, 07:19:18 AM
Thanks for the courtesy Dave, and thanks for the code.
Title: Re: Setting an existing Door Style
Post by: DaveW on July 27, 2006, 08:55:20 AM
Your more then welcome. Once you spend a little time with it you will find it work pretty well. You may not need it now, but you may need it in the future.

Bob, TOO FUNNY! I get it now. :)

BTW, I can be pretty stupid at this programming stuff. You can tell him I said that. lol
Title: Re: Setting an existing Door Style
Post by: BAshworth on July 27, 2006, 10:31:15 AM
Don't say stuff like that.  I'm going to be hanging around with him all weekend, he doesn't need head enlargement therapy right now.

Hmm.. gotta get that pinky ring shined up if it's going to start getting kissed. :D

I agree, it's a BS way of setting the active object style within ADT.  From what I understood, more recent versions of the ADT object model are more comprehensive in what they expose directly through VBA.  I use ADT 2004.

I got to thinking, and I haven't tested it, but it might work if you add a wall to the drawing of a particular style, then delete it via code.  I know that if you add a wall manually, it defaults to the last style that was drawn when you go to draw the next one.  However, I don't know if the same happens when you add a wall via code.

Of course, at that point, you might have been ahead to go ahead and write the function to modify the registry entry.  It's not all that difficult to do, and once you have the function written, you can expand it to set all sorts of other object styles as current.

Title: Re: Setting an existing Door Style
Post by: Matersammichman on July 27, 2006, 10:41:23 AM
Walls are the easy one...Doors on the other hand fight against you when using SendCommand
...try it, you won't like it.
Title: Re: Setting an existing Door Style
Post by: BAshworth on July 27, 2006, 10:51:26 AM
Walls are the easy one...Doors on the other hand fight against you when using SendCommand
...try it, you won't like it.

Sorry, I meant doors.  I was thinking doors, but typed walls. Yes I completely understand your frustration.  I have never experienced more WTF?! moments than when I started working with the ADT object model. Are you looking to just set the active style, or do you also want to leave it in the middle of the dooradd command so the user can place the door?
Title: Re: Setting an existing Door Style
Post by: Matersammichman on July 27, 2006, 10:56:31 AM
DEFINITELY the latter...(Middle of the code)...
and If you have code to do this flawlessly, you get the Guru cap for the day!!!
Title: Re: Setting an existing Door Style
Post by: BAshworth on July 27, 2006, 11:10:43 AM
DEFINITELY the latter...(Middle of the code)...
and If you have code to do this flawlessly, you get the Guru cap for the day!!!


Code: [Select]
ThisDrawing.SendCommand ("dooradd" & vbCr & vbCr & "ST" & vbCr & "Your wall style here" & vbCr)

However that leaves us at adding a free-standing door.  Not one connected to a wall assembly.   I'll give this some more work today to figure the rest out.   *grumbles about f'n dooradd command.*
Title: Re: Setting an existing Door Style
Post by: DaveW on July 27, 2006, 02:21:52 PM
A few notes on ADT.

Both ADT and Revit are suppose to follow the design/build principle set forth as concept by the PhD's at the top technical universities. Autodesk got wind of their concept and bought Revit to take it to the next level. Unfortunately, they never understood the "entire" concept. They understood to concept of making objects react to each other and thought they could run with it. What they missed was the fundamental understanding not forcing the user to predefine a design and still get the manufacturing information. The reason being, at that time no company anywhere knew how to do it. That is what design/build was just a concept. As it stands right now, they are driving / creating the parts with a database. This starting point of driving/ creating voids the basic principal of design/build, as the user never really has true design freedom and can still get the manufacturing information. The problem lies in the fact that you must have the 3D distances AND associate those distances or dimensions to the Length, Width, and Thickness. Because the core modeling engine data base is really only points in space that do not have orientation information, they are just a point, no company every figure out how to get the Length, Width, and, Thickness without driving the drawing. This only applies to industries where the source raw material is solid. The rapid prototyping industry is unaffected and can do design/build, because their source raw material is a liquid. ADT and many other driven softwares can work well and automate a great many things. The problems always come up when you are creating something that the formulas were not created to handle. In building custom structures, even if you had enough formulas, the basic end user could not remember them all.

About the VB in ADT. There is only one company that has an OEM to ADT. That is Americad. I talked with them at great length a while back and they told me that their licence prevents them from adding any code or method that can extract information that is not already available through their exposed methods! What a bummer, huh?

Enough trivia.

Have fun guys,

Dave