Author Topic: File Type Actions  (Read 5592 times)

0 Members and 1 Guest are viewing this topic.

M-dub

  • Guest
File Type Actions
« on: July 15, 2004, 09:48:03 AM »
Under the File Types tab in the Folder Options, I'm trying to create an action for our GP4 files (raster images) so that when one is double clicked, it is automatically inserted into a new drawing file in Acad.  I'm not really looking for someone to outright tell me exactly what to type in there, but more how to figure it out for myself.  If it would be much easier just to tell me what to type, then I guess that would be great too, I guess.  I just want to try to figure it out for myself, but I don't know where to look to start learning.


Any Ideas?

Thanks a lot,
Mike

hendie

  • Guest
File Type Actions
« Reply #1 on: July 15, 2004, 10:31:14 AM »
I'm not sure but I don't think you can do that through the file types thingy.
you can specify certain actions but what you want to do requires a whole series of actions to take place.
you may be able to create a batch file to carry out the actions and run the bacth file from the double click though

hendie

  • Guest
File Type Actions
« Reply #2 on: July 15, 2004, 10:41:55 AM »
It may be possible using DDE
the info I have on DDE is very limited. I have managed to initiate DDE conversations between AMW & Word to transfer data from AMW memo fields into Word documents and format it, but as I mentioned, it's very limited.
VBscript may be another possibility. Keith would probably be in a better position than me to answer this one

M-dub

  • Guest
File Type Actions
« Reply #3 on: July 15, 2004, 10:52:18 AM »
Thanks a lot Hendie,
   I'm going to investigate further and will post my findings.

Cheers!
Mike

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
File Type Actions
« Reply #4 on: July 15, 2004, 12:45:47 PM »
You can create a VB(a) program that will insert the image into a new drawing when double clicked in the windows environment.

Tell me this...

When you insert the image from the AutoCAD environment, what steps do you take... exactly...

I will use that to create an executable that you can put in your Program Files to do the action from Windows
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

M-dub

  • Guest
File Type Actions
« Reply #5 on: July 15, 2004, 01:29:44 PM »


You're truly a kind, kind soul!

Normally, we'd find the drawing using windows Find Files / Search utility, then drag and drop the file into a new drawing in AutoCAD.  The new drawing has to be created before this occurs, of course.  When we insert an image, it almost always goes to 0,0,0.  Basically, we consider all of the scaled drawings that were scanned to be NTS anymore, so they're all inserted at a scale factor of 1 and rotation angle of 0.

Anything beyond that is done with CAD Overlay / (Now Raster Design).

The problem is that I want the inept to be able to simply double click on the gp4's, and cal's and have it do the above all in one step.

That's about it, BUT...........


On top of that, if the raster file is modified in any way, it is standard procedure for the user to save it, which 99.9% of the time, must match the name of the the raster file or vise versa.  This can get a little messy though too because sometimes, there's an additional prefix that must be added to old drawings if it has not yet been added to the drawing number.

Here's an example of that scenario:

1.)  (If I don't use the IINSERT command or the Image Manager), I find QDG27753.gp4 under the O:\Drawings\A-Ammon\B-Ammon\Q-Inst directory.
2.)  Drag it into a new drawing in AutoCAD and make modification.
3.)  Save both the dwg file and the gp4 files as ABQ-QDG27753.dwg & gp4 and make sure that the original QDG27753.gp4 file is deleted.

Does that make sense?  Let me know if I should just go pound salt, but all I'm really trying to do is have it autoinsert into acad so someone can view / print (in most cases) just like they would a DWG file.

Thanks a lot Keith!  

PS - If possible, it would be really nice if I could see your VB code to give me an idea of what you're doing.  I'm in the early phases of a VB course and just learning, but really liking it...I just need to see more examples of what's out there and how it's done.  Know what I mean?  If you'd rather not, that's totally fine too!  Thanks

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
File Type Actions
« Reply #6 on: July 15, 2004, 01:31:53 PM »
So basically insert image at 0,0,0 scale of 1 in a new drawing...

If so.. should be a cinch
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

M-dub

  • Guest
File Type Actions
« Reply #7 on: July 15, 2004, 01:34:51 PM »
LOL!
Yeah...to make a real long story short!

;)
Cheers!

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
File Type Actions
« Reply #8 on: July 15, 2004, 10:21:05 PM »
Ok, here it is... lemme know if'n it isn't good enough...

Ok, I was lazy and didn't change the icon for the proggie ... I think you can live without a special icon...
If you run the executable it will open a "Select Image File" dialog. You can select any of the AutoCAD 2004 supported image formats (this also works in 2000 & 2002)
I didn't take the time to create an install that makes the file associations for you... I figured you could do that easily enough.
Once you set up the file associations you want to use with this program, you can double click the image file and it will automatically open in a new drawing. If AutoCAD is not open, it will open it for you... if AutoCAD is open, it will use the one that is open.
Once an image is opened, it is set current,  zoomed extents, and the AutoCAD window is maximized... point your concerns to someone else...

That'll be a million bucks deposited to my paypal account (I trust you are able to pay)
Oh.. if'n you want to see the source code, lemme know and I will post it....
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

M-dub

  • Guest
File Type Actions
« Reply #9 on: July 15, 2004, 10:39:37 PM »
Thanks a lot, Keith!  I'll try it as soon as I get to work tomorrow.

I'll have to pay you in installments.....lots and lots of installments...

;)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
File Type Actions
« Reply #10 on: July 15, 2004, 11:18:24 PM »
that'll be fine....
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

M-dub

  • Guest
File Type Actions
« Reply #11 on: July 16, 2004, 08:00:18 AM »
>I didn't take the time to create an install that makes the file associations for you... I figured you could do that easily enough.

You figured wrong :oops: :oops: :oops:

I'm sorry, Keith, but I'm just too new to VB and am unfamiliar with this.  How is that done or what can I look up to help me get there?

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
File Type Actions
« Reply #12 on: July 16, 2004, 08:53:48 AM »
File associations are rather easily done...

Open any folder... go to "Tools -> Folder Options"
select the FileTypes Tab
Find the extensions you want opened in AutoCAD automatically when double clicking on them
highlight the extension, select the Change button
in the resulting window browse to the InsertImage executable.. make sure you have the InsertImage executable where it's final location will be otherwise if you move it the file association may fail.
Select Ok, and close the window(s)

All done....

Now for the code.....commented extensively for your ease of understanding


Code: [Select]

'declare API function to show the window (i.e. AutoCAD)
Declare Function ShowWindow Lib "User32" (ByVal hWnd As Long, ByVal Msg As Long) As Long
'declare API function to find a window (i.e. AutoCAD)
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal owner As Long, ByVal Title As String) As Long
'declare API function to display an "Open File" window
Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
'Type structure for "Open File" window (see MSDN API help for more information of typedefs
Private Type OPENFILENAME
    lStructSize       As Long
    hwndOwner         As Long
    hInstance         As Long
    lpstrFilter       As String
    lpstrCustomFilter As String
    nMaxCustFilter    As Long
    nFilterIndex      As Long
    lpstrFile         As String
    nMaxFile          As Long
    lpstrFileTitle    As String
    nMaxFileTitle     As Long
    lpstrInitialDir   As String
    lpstrTitle        As String
    flags             As Long
    nFileOffset       As Integer
    nFileExtension    As Integer
    lpstrDefExt       As String
    lCustData         As Long
    lpfnHook          As Long
    lpTemplateName    As String
End Type

'Main program ... set project to default execute Sub Main
Sub Main()
'define variables
 Dim CmdArg As String
 Dim Ext As String
 Dim LoadFile As Boolean
 
 'get any command line arguments passed this should only be a file name if last 3 or 4 chars do not match an accepted
 'file type, the user is notified below
 CmdArg = Command()
 'if we got a command line argument
 If CmdArg <> "" Then
 'lets see if there is a 3 char extension
 If UCase(Mid$(CmdArg, Len(CmdArg) - 4, 1)) = "." Then
 'if so grab the last 3 chars
  Ext = UCase(Mid$(CmdArg, Len(CmdArg) - 3, 3))
 'otherwise lets see if there is a 4 char extension
 ElseIf UCase(Mid$(CmdArg, Len(CmdArg) - 5, 1)) = "." Then
 'if so grab the last 4 chars
  Ext = UCase(Mid$(CmdArg, Len(CmdArg) - 4, 4))
 End If
 'lets see if the extension (Ext) matches our filter for type
 Select Case Ext
 'list of acceptable file type extensions separated by comma, capitalized and enclosed in quotes
  Case "BMP", "RLE", "DIB", "CAL", "RST", "GP4", "MIL", "CG4", "FLC", "FLI", "BIL", "IG4", "IGS", "JPE", "JPG", "JPEG", "PCX", "PCT", "PNG", "RLC", "TGA", "TIF", "TIFF"
 'if the file was of the correct type (i.e. extension) set a boolean value to true
  LoadFile = True
 End Select
 End If
 'if we have a valid command line argument and it passed the extension test
 If (CmdArg <> "") And (LoadFile = True) Then
 'load the image identified by CmdArg
  LoadImage (CmdArg)
 'otherwise if we have a command line argument
 ElseIf (CmdArg <> "") Then
 'it did not pass the extension test so notify the user that it is not supported
  MsgBox "Unrecognized File Format", vbExclamation, "InsertImage ERROR"
 Else
 'if we did not get a command line argument
 'it is in a while statement just in case the "Open File" window returns
 'an empty string, as such it will simply retain the open file dialog
  While CmdArg = ""
 'call the "Open File" window and grab the return value
   CmdArg = Open_Comdlg32
  Wend
 'if the user didn't cancel the "Open File" window we should have a valid file name
  If CmdArg <> "0" Then
 'using the file name (i.e. CmdArg) call the LoadImage subroutine
   LoadImage (CmdArg)
  End If
 End If
End Sub

'Code to display "Open File" dialog....

Function Open_Comdlg32()
'define variables
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim strFilter As String

'set our OpenFile object structure size to the code size of our variables
OpenFile.lStructSize = Len(OpenFile)
'assign the filter types
'that will be seen in the combo box on the window
'the format is simple to follow, "FILEDESC(*.EXT;*.EXT)" & Null char & "*.EXT;*.EXT" & Null Char
strFilter = "All Image Files" & Chr(0) & "*.bmp;*.rle;*.dib;*.cal;*.rst;*.gp4;*.mil;*.cg4;*.flc;*.fli;*.bil;*.ig4;*.igs;*.jpe;*.jpg;*.jpeg;*.pcx;*.pct;*.png;*.rlc;*.tga;*.tif;*.tiff" & Chr(0) & _
            "BMP(*.bmp;*.rle;*.dib)" & Chr(0) & "*.bmp;*.rle;*.dib" & Chr(0) & _
            "CALS1 (*.cal;*.rst;*.gp4;*.mil;*.cg4)" & Chr(0) & "*.cal;*.rst;*.gp4;*.mil;*.cg4" & Chr(0) & _
            "FLIC (*.flc;*.fli)" & Chr(0) & "*.flc;*.fli" & Chr(0) & _
            "GEOSPOT (*.bil)" & Chr(0) & "*.bil" & Chr(0) & _
            "IG4 (*.ig4)" & Chr(0) & "*.ig4" & Chr(0) & _
            "IGS (*.igs)" & Chr(0) & "*.igs" & Chr(0) & _
            "JFIF (*.jpe;*.jpg;*.jpeg)" & Chr(0) & "*.jpe;*.jpg;*.jpeg" & Chr(0) & _
            "PCX (*.pcx)" & Chr(0) & "*.pcx" & Chr(0) & _
            "PICT (*.pct)" & Chr(0) & "*.pct" & Chr(0) & _
            "PNG (*.png)" & Chr(0) & "*.png" & Chr(0) & _
            "RLC (*.rlc)" & Chr(0) & "*.rlc" & Chr(0) & _
            "TGA (*.tga)" & Chr(0) & "*.tga" & Chr(0) & _
            "TIFF (*.tif;*.tiff)" & Chr(0) & "*.tif;*.tiff" & Chr(0)

'with our "Open File" window, use the following data
With OpenFile
    .lpstrFilter = strFilter
    .nFilterIndex = 1
    .lpstrFile = String(4096, 0)
    .nMaxFile = Len(.lpstrFile) - 1
    .lpstrFileTitle = .lpstrFile
    .nMaxFileTitle = .nMaxFile
    .lpstrTitle = "Select Image File"  'our open file title
    .flags = 524288 'flags for open file new style with single file selections
End With
'call the API function, and pass out OpenFile struct to the command
'then grab the return value
lReturn = GetOpenFileName(OpenFile)
'if it does not return 0 the user pressed OK
    If lReturn <> 0 Then
'so lets return the file name to the calling function
      Open_Comdlg32 = OpenFile.lpstrFile
    Else
'otherwise the user canceled so return a "0"
'note I used a string simply because it was simpler to facilitate
'the "string" type defined above
      Open_Comdlg32 = "0"
    End If
End Function

'sub to load the image into AutoCAD

Sub LoadImage(ByVal ImageName As String)
'Define our variables, note that AC(AutoCAD) and NewDwg are defined as objects this lets us load the
'required type libraries dynamically making it work for 2000, 2002, 2004 and 2005
  Dim AC As Object
  Dim NewDwg As Object
  Dim InsPnt(2) As Double
 
'set the insertion point to 0,0,0
  InsPnt(0) = 0#: InsPnt(1) = 0#: InsPnt(2) = 0#

'Set AC(AutoCAD) to the AutoCAD object by calling our subroutine below
  Set AC = GetAcadObject
'Find the AutoCAD window, and show it maximized
  ShowWindow FindWindow(0&, AC.Caption), &H3
'create a new drawing in AutoCAD
  Set NewDwg = AC.Documents.Add()
'activate it
  NewDwg.Activate
'Add a raster image into modelspace as specified by ImageName at our InsPnt with a scale of 1 and rotation of 0
  NewDwg.ModelSpace.AddRaster ImageName, InsPnt, 1, 0
'zoom the drawing to extents
  AC.ZoomExtents
End Sub

'Function to find AutoCAD or load it if not found
Function GetAcadObject() As Object
'Get the AutoCAD.Application as defined in the registry
 Set GetAcadObject = GetObject(, "AutoCAD.Application")
 'if we could not get it, then it is not running so...
    If Err <> 0 Then
        Err.Clear
        'lets create it ..i.e. start AutoCAD
        Set GetAcadObject = CreateObject("AutoCAD.Application")
        If Err <> 0 Then
        'if we can't start it then notify the user
            MsgBox "Could not load or find AutoCAD.", vbExclamation
            End
        End If
    End If
End Function
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

M-dub

  • Guest
File Type Actions
« Reply #13 on: July 16, 2004, 09:17:33 AM »
:oops:  I know how to create associations!  I was thinking too much into it...
I tried that, but it keeps giving me an error.
I've tried a few different configurations of the association, but each one give me the error.  When I run the program using the EXE, it works fine though... :?:

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
File Type Actions
« Reply #14 on: July 16, 2004, 09:57:34 AM »
Hmmm....I had no problems.. what file type are you sending?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie