PViewports using VBA

Discussion in 'AutoCAD' started by PeteB, Aug 8, 2003.

  1. PeteB

    PeteB Guest

    Hi Guys
    I'm trying to put together a VBA macro/program to create a set of drgs with
    raster attachments using the raster image name as the dwg filename. There
    could be anything from 5 to 100 or so raster images that require 'attaching'
    to a .dwg file for ease of plotting.
    The problem arises when creating a PViewport (of a size equivalent to the
    raster image size) and then trying to save the .dwg.
    It is saved OK but the PViewport is not there on re-opening the dwg.
    The code used to create the PViewport is shown below.

    If AttachImage(imageFile) Then
    ZoomExtents
    imgSize = GetImageSize(imgWidth, imgHeight)
    If .ActiveSpace = acModelSpace Then
    .ActiveSpace = acPaperSpace
    End If
    Set Lay1 = .Layouts.Item("Layout1")
    Set Lay1 = .ActiveLayout
    Lay1.name = LayoutName(imgSize)
    .ActiveLayout.CanonicalMediaName = MediaSize(imgSize)
    For Each PView In .PaperSpace
    PView.Delete
    Next PView
    .Regen acActiveViewport
    LayerTest
    Pview_Centre(0) = imgWidth / 2
    Pview_Centre(1) = imgHeight / 2
    Pview_Centre(2) = 0
    Set PView = .PaperSpace.AddPViewport(Pview_Centre, imgWidth,
    imgHeight)
    PView.Display True
    .MSpace = True
    ZoomExtents
    .MSpace = False
    PView.StandardScale = acVp1_1
    PView.DisplayLocked = True
    intPos = InStr(1, strFName, ".", vbTextCompare)
    strFName = Left(strFName, intPos - 1)
    .SaveAs (strFilePath & strFName), ac2000_dwg
    End If

    Hope someone can help 'cos this is driving me nuts.
    BTW this all happens in SDI mode
    cheers
    PeteB
     
    PeteB, Aug 8, 2003
    #1
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.