Hi, I am contemplating writing a program to create custom palettes in AutoCAD 2005 and later versions using either VBA or .NET. I'd be interested in the practicality of this. Is there any sample code available ? Any traps in the process ? -- Laurie Comerford CADApps www.cadapps.com.au
Hi Tony, Thanks, you've just saved me hours of searching, experimenting and reading. It may be tedious, but I'll take the first path as I do not have the skills (or the time to learn them) to tackle the second path. The next step is to start analysing the format of the palette definition files. In the main I want to do two things. 1 Provide access to program calls defined in an MNL file. This probably does not need to be programmed, as the palette could be pre-defined and distributed with the program. 2 My program generates a series of drawing files with a WBLOCK process. I want to put a thumbnail of the drawings on the palette and then Xref the drawings enabling the user to "assemble them" into a finished drawing. This will have to be programmed to add the block each time it is created, but not to add it when the design is changed and the drawing file is re-created due to the design change. -- Laurie Comerford CADApps www.cadapps.com.au
The API for tool palettes is not exposed to VBA (or .NET), so what you can do is limited to generating the XML source (.XTP) file for a palette. For greater access to the extensive ObjectARX/COM toolpalette API from VBA or ActiveX, you would need to build an ObjectARX/ActiveX library that can expose the needed functionality.
Hi, I've now looked at the files necessary for a tool palette and found they can be created programmatically, but that there are some serious difficulties. 1 The files contain long random strings and I have no guidance as to acceptability of the strings if I simply generate them myself 2 The files contain references to two .PNG files to display the graphics. It is not at all obvious how one could generate these files. 3 It would appear the user would have to import the file to the palette. This work would be nearly as complex as simply using Windows Explorer to drag the blocks into a palette. Hence, for the time being, pending Autodesk providing the needed APIs to build a palette I'm going to abandon this project. -- Laurie Comerford CADApps www.cadapps.com.au
Laurie, Too bad you're electing to abandon this, as I think it would be a viable and highly useable tool for many. I've started work on something like this myself, and am willing to share my progress. Unfortunately I don't get a lot of time for development here. Anyway, if any of this stuff can help you, great, if not then oh well. As far as your comments here: 1 the random string I believe is simply a GUID, which can be generated using the utility I've enclosed below. 2 don't know about this one... maybe a batch utility or program run on the side can use the drawing thumbnail to generate a png? 3 I believe loading a new palette is as easy as just storing it in the Autodesk palette directory under documents & settings (see function Palette_Path below). I had this up and running, generating the text file (xml) as well, but couldn't work out a couple little bugs with the xml format. ' . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . ' 'Returns globally unique identifier ' 'Required SubRoutines: 'FormatGUIDData4 'PadLeft ' Public Function CreateGUID() As String Dim sGUID As String 'store result here Dim tGUID As GUID 'get into this structure If CoCreateGuid(tGUID) = 0 Then 'use API to get the GUID With tGUID 'build return string sGUID = "{" & PadLeft(Hex(.Data1), mciLen * 2) & "-" sGUID = sGUID & PadLeft(Hex(.Data2), mciLen) & "-" sGUID = sGUID & PadLeft(Hex(.Data3), mciLen) & "-" sGUID = sGUID & FormatGUIDData4(.Data4()) End With sGUID = sGUID & "}" 'ending brace CreateGUID = sGUID End If End Function ' . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . ' 'Subroutine required for CreateGUID ' Private Function FormatGUIDData4(aryData4() As String * 1) As String Dim i As Integer 'loop thru the array Dim sGUID As String 'store result here Dim sTemp1 As String 'first part here Dim sTemp2 As String 'second part here For i = LBound(aryData4()) To UBound(aryData4()) 'process string array If i < 2 Then 'first part sTemp1 = sTemp1 & Hex(Asc(aryData4(i))) Else 'second part sTemp2 = sTemp2 & Hex(Asc(aryData4(i))) End If Next sGUID = PadLeft(sTemp1, mciLen) & "-" & PadLeft(sTemp2, mciLen * 3) 'pad left with zeros FormatGUIDData4 = sGUID 'return what we created End Function ' . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . ' 'Subroutine required for CreateGUID ' Private Function PadLeft(sString As String, iLen As Integer) As String ' Pad with left zeros if needed Dim sTemp As String sTemp = Right$(String$(iLen, "0") & sString, iLen) PadLeft = sTemp End Function ' . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . ' 'Retrieves tool palette path from preferences if possible, otherwise uses installation directory ' 'Function: 'Returns tool palette file path ' Public Function Palette_Path() As String Dim sTemp As String Dim acPref As AcadPreferences Dim sPaths() As String Dim i As Long Set acPref = ThisDrawing.Application.Preferences sTemp = acPref.Files.ToolPalettePath If UCase(Right(sTemp, 11)) = "TOOLPALETTE" Then 'this is the right path sTemp = sTemp & "\Palettes\" ElseIf InStr(1, UCase(sTemp), "TOOLPALETTE") > 0 Then 'truncate just after support sTemp = Left(sTemp, InStr(1, UCase(sTemp), "TOOLPALETTE") + 11) & "\Palettes\" Else 'worst case, use application path sTemp = Support_Path End If Palette_Path = sTemp Set acPref = Nothing End Function ' #VBIDEUtils#************************************************************ ' * Programmer Name : Waty Thierry ' * Web Site : www.geocities.com/ResearchTriangle/6311/ ' * E-Mail : ' * Date : 22/10/98 ' * Time : 15:50 ' * Module Name : GUID_Module ' * Module Filename : sGUID.bas Kevin
What 'long random strings' are you referring to? PNG files are Portable Network Graphics files, which is a common graphics file format that many image editing programs support.
Hi Tony, Here's a typical one: idValue="{6442ECC1-5F16-49C3-B89E-3999B89C34B7}" id="{6442ECC1-5F16-49C3-B89E-3999B89C34B7}" Each one is repeated in the file and they are obviously used for identifying components and then for setting the order of appearance in the palette. I'm sure Kevin is correct in his notes about them, but I have no theoretical knowledge of GUIDs. PNG files are certainly as you say, and AutoCAD has a PNGOUT command. But that command creates PNG files which match the current graphic screen size and require the user to select the objects to be included. I guess this could be done with the SendCommand process if there is no API for the PNGOUT command, but it would be messy and more than one PNG file is referenced for each block. Steps needed would include: 1 Set back ground to white 2 Generate drawing and wblock it out - This already happens with the program. 3 Resize graphics area of screen to 64 pixels by 64 pixels and zoomed to the bounding box of the required data. Run the PNGOUT command (or it's API equivalent) passing the necessary file name which appears to be BlockName64.png. Also select all the objects to pass to the command. 4 Resize graphics area of screen to 32 pixels by 32 pixels and zoomed to the bounding box of the required data. Run the PNGOUT command passing the necessary file name which appears to be BlockName32.png.. Also select all the objects to pass to the command. 5 Cycle through 2, 3 and 4 for each drawing generated 6 Restore the screen when finished. If I'm right in this speculation, I can't imagine it happening quickly or in a visually satisfying way for the user. Although in most cases between 2 and 20 would be expected, running the program as it now exists could generate hundreds of drawings given a large number of roads and intersections in a project. -- Laurie Comerford CADApps www.cadapps.com.au