Author Topic: VBA Image control  (Read 6868 times)

0 Members and 1 Guest are viewing this topic.

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: VBA Image control
« Reply #15 on: March 15, 2006, 03:26:02 PM »
thankss
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: VBA Image control
« Reply #16 on: March 15, 2006, 03:27:56 PM »
No problem, gave me an excuse to play with some code, never enough time to do that anymore.

Jeff_M

  • King Gator
  • Posts: 3946
  • C3D user & customizer
Re: VBA Image control
« Reply #17 on: March 15, 2006, 03:41:31 PM »
Wouldn't it be easier to just change the ImagePath and Name properties to match the new Image, rather than inserting a new one and deleteing the old one? Plus that way, if there is any Xdata attached to it, it won't be lost.

Bob Wahr

  • Guest
Re: VBA Image control
« Reply #18 on: March 15, 2006, 03:54:55 PM »
Mostly because that would make way too much sense.  Thanks for the reality check Jeff.

Code: [Select]
Sub RastaRenameMon()

  Dim objSelSets As AcadSelectionSets
  Dim objSelSet As AcadSelectionSet
  Dim intType(0) As Integer
  Dim varData(0) As Variant
  Dim objImg As AcadRasterImage
  Dim strImgName As String
  Dim strDwgName As String
  Dim strImgExt As String
  Dim strImgPath As String
  Dim strNewName As String
 
  strDwgName = Left(ThisDrawing.Name, Len(ThisDrawing.Name) - 4)
  Set objSelSets = ThisDrawing.SelectionSets
  For Each objSelSet In objSelSets
    If objSelSet.Name = "Imagen" Then
      objSelSets.Item("Imagen").Delete
      Exit For
    End If
  Next
  Set objSelSet = objSelSets.Add("Imagen")
  intType(0) = 0
  varData(0) = "IMAGE"
  objSelSet.Select acSelectionSetAll, _
  filtertype:=intType, filterdata:=varData
  If objSelSet.Count > 0 Then
  For Each objImg In objSelSet
    strImgExt = Right(objImg.ImageFile, 4)
    strImgName = objImg.Name
    strImgPath = Left(objImg.ImageFile, Len(objImg.ImageFile) - Len(strImgName) - 4)
    strNewName = strImgPath & strDwgName & strImgExt
    FileCopy objImg.ImageFile, strNewName
    objImg.ImageFile = strNewName
    objImg.Name = strDwgName
    Kill strImgPath & strImgName & strImgExt
  Next objImg
  End If
End Sub

Bryco

  • Water Moccasin
  • Posts: 1850
Re: VBA Image control
« Reply #19 on: March 15, 2006, 04:00:01 PM »
Code: [Select]
Private Sub RenameImages()

    Dim i As Integer, sImageName As String
    Dim oImage As AcadRasterImage
    Dim SS As AcadSelectionSet
    Dim sName As String
    Dim NewPath As String
    Dim Fs As Object
    'Dim F As Object
    Dim F As File
    Dim filespec As String
   
    Set Fs = CreateObject("Scripting.FileSystemObject")
    sName = "UE06-03-0012"
 
    Set SS = sset(0, "Image")
    If SS.Count > 0 Then
        For Each oImage In SS
             filespec = oImage.ImageFile
             Set F = Fs.GetFile(filespec)
             NewPath = Replace(filespec, oImage.Name, sName)
             F.Copy NewPath
             oImage.Name = sName
             oImage.ImageFile = NewPath
             Debug.Print F.Path
             F.Delete
        Next oImage
    End If
    SS.Delete

End Sub

Bob Wahr

  • Guest
Re: VBA Image control
« Reply #20 on: March 15, 2006, 04:03:06 PM »
I get "User-defined type not defined" on the line     Dim F As File

Bob Wahr

  • Guest
Re: VBA Image control
« Reply #21 on: March 15, 2006, 04:04:19 PM »
For that matter, NewPath doesn't work.  Is that VB or VBA?

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: VBA Image control
« Reply #22 on: March 15, 2006, 04:11:58 PM »
i think   a little of both.  Add the Ms scripting reference i think
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: VBA Image control
« Reply #23 on: March 15, 2006, 04:30:53 PM »
head pulled out, um yeh, makes sense.

Bryco

  • Water Moccasin
  • Posts: 1850
Re: VBA Image control
« Reply #24 on: March 15, 2006, 06:20:41 PM »
Had to run so I posted without the function. Vba . Bob does the replace not work for you? acad2000?
Here's the sset function, I like the ease of use it has.
Code: [Select]
Public Function sset(FilterType, FilterData As Variant, Optional ssName As String = "SS") As AcadSelectionSet
   
    Dim oSSets As AcadSelectionSets
    Set oSSets = ThisDrawing.SelectionSets
    For Each sset In oSSets
        If sset.Name = ssName Then
            sset.Delete
            Exit For
        End If
    Next
    Dim FType() As Integer
    Dim FData() As Variant
    Dim i As Integer
    If IsArray(FilterType) = False Then
        If IsArray(FilterData) = False Then
            ReDim FType(0)
            ReDim FData(0)
            FType(0) = FilterType
            FData(0) = FilterData
        Else
            Exit Function
        End If
    Else
        If UBound(FilterType) <> UBound(FilterData) Then
            Exit Function 'They must be pairs
        End If
       
        ReDim FType(UBound(FilterType))
        ReDim FData(UBound(FilterType))
        For i = 0 To UBound(FilterType)
            FType(i) = FilterType(i)
            FData(i) = FilterData(i)
        Next
    End If
   
    Set sset = ThisDrawing.SelectionSets.Add(ssName)
    sset.Select 5, FilterType:=FType, FilterData:=FData
    'To use this function for single filter
    'Set SS = SSet(0, "insert")
    'For multiple filter
    'Set SS = SSet(array(0,2),array("insert",oBlock.name)) 'must be pairs
End Function

Bob Wahr

  • Guest
Re: VBA Image control
« Reply #25 on: March 15, 2006, 06:56:41 PM »
With the sset function, and after referencing the Scripting, everything was swell.

Bryco

  • Water Moccasin
  • Posts: 1850
Re: VBA Image control
« Reply #26 on: March 15, 2006, 08:04:51 PM »
Bob or CmdrDuh , you don't know where I could get a help file for scripting do you?

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: VBA Image control
« Reply #27 on: March 15, 2006, 09:17:18 PM »
Im leaving town for a few days, Ill look on monday
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

Chuck Gabriel

  • Guest
Re: VBA Image control
« Reply #28 on: March 16, 2006, 07:46:01 AM »
There is some documentation of scripting objects in the help file for VBA.  Just hit F1 while in the IDE, pick the Contents tab, and expand Objects.  You will see things like Dictionary, File, Folder, and etc. that all come from the scripting library.

Bryco

  • Water Moccasin
  • Posts: 1850
Re: VBA Image control
« Reply #29 on: March 16, 2006, 10:09:35 AM »
Thanks Chuck.