VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Window plot using VBA - strange offset

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
kasperwuyts
8657 Views, 8 Replies

Window plot using VBA - strange offset

Hello all

 

Beginner question about plotting a window with VBA:

 

I am using an exact copy of this sample subroutine:

 

http://knowledge.autodesk.com/support/autocad-structural-detailing/downloads/caas/CloudHelp/cloudhel...

 

When doing this the plot area is the correct size and shape, but it offset quite far to the lower right, meaning the preview is always empty. I don't know what is causing this offset, I thought it might have something to do with coordinate systems or dynamic input, but playing around with these doesn't yield any better results.

 

The problem appears to be drawing related (as I've tested it succesfully with another drawing), but I don't know what is causing it. Does anyone have an idea where I went wrong with my drawing?

 

Thanks in advance

Kasper Wuyts

 

PS:

Judging from the title of the page, this might be a solution, but I only have access to google and Autodesk.com at work, so unfortunately I am unable to watch this.

https://www.google.be/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&ved=0CC0QFjAB&url=http...


Best regards
Kasper Wuyts
_______________________________________________________________________________
If this post solves your problem, clicking the 'accept as solution' button would be greatly appreciated.
8 REPLIES 8
Message 2 of 9
RICVBA
in reply to: kasperwuyts

plotting-windowplot manually you get it right. but there appears an "original" window plot area that's offset some (+190000,-67000) before you force it to the one you select manually. and that offset is quite the one you suffer

 

maybe this drawing has to do with a wcs-ucs issue. but it's just a guess

Message 3 of 9
RICVBA
in reply to: kasperwuyts

A quick search through the web only confirmed that odd and unpredictable behaviour for the SetToWindow method in conjunction with acWindow PlotType property

so it seems to me a workaround is the only way out

since acView PlotType property works properly, you can first zoom to the chosen window and then plot the current display, as follows (I marked code lines added and/or revised by me)

Sub Example_SetWindowToPlot()
    ' This example allows the user to define an area in the current layout
    ' and displays a plot preview of the defined area.
    '
    ' * Note: You have to exit the
    ' plot preview before the VBA example will stop and control will be returned

    AppActivate ThisDrawing.Application.Caption

    Dim point1 As Variant, point2 As Variant
    
    ' Get first point in window
    point1 = ThisDrawing.Utility.GetPoint(, "Click the lower-left of the window to plot.")
    ReDim Preserve point1(0 To 1)   ' Change this to a 2D array by removing the Z position
    
    ' Get second point in window
    point2 = ThisDrawing.Utility.GetPoint(, "Click the upper-right of the window to plot.")
    ReDim Preserve point2(0 To 1)   ' Change this to a 2D array by removing the Z position
    
    ' Send information about window to current layout
    ThisDrawing.ActiveLayout.SetWindowToPlot point1, point2
    
    ' Read back window information
    ThisDrawing.ActiveLayout.GetWindowToPlot point1, point2
    
    MsgBox "Press any key to plot the following window:" & vbCrLf & vbCrLf & _
           "Lower Left: " & point1(0) & ", " & point1(1) & vbCrLf & _
           "Upper Right: " & point2(0) & ", " & point2(1)
          
    '----------------------------------------
    ' added by RICVBA
    Dim point1w(0 To 2) As Double
    Dim point2w(0 To 2) As Double
    point1w(0) = point1(0): point1w(1) = point1(1): point1w(2) = 0
    point2w(0) = point2(0): point2w(1) = point2(1): point2w(2) = 0
    ZoomWindow point1w, point2w ' make the current display fit the "window to plot"
    '----------------------------------------
    
    ' Plot the current display
    ThisDrawing.ActiveLayout.ConfigName = "DWG to PDF.pc3"
    ThisDrawing.ActiveLayout.PlotType = acDisplay ' <--- revised by RICVBA
    ThisDrawing.ActiveLayout.CenterPlot = True ' <--- added by RICVBA
    ThisDrawing.ActiveLayout.StandardScale = acScaleToFit ' <--- added by RICVBA
    ThisDrawing.Plot.DisplayPlotPreview acFullPreview
    
    ZoomPrevious ' restore the previous zoom (optional) ' <--- added by RICVBA
    
End Sub

where I also added some layout plotting configurations to make sure the chosen window entirely fits the paper size and centered into it 

 

hope this can help you

 

bye

 

Message 4 of 9
kasperwuyts
in reply to: RICVBA

This does seem to work. So I'm accepting it as a solution, although I should modify it for correct scaling. Also, I wonder if the screen hopping performs decently when used to plot 30 drawings from one file simultaneously. I'm going to try some stuff out this weekend.

 

Thanks!


Best regards
Kasper Wuyts
_______________________________________________________________________________
If this post solves your problem, clicking the 'accept as solution' button would be greatly appreciated.
Message 5 of 9
RICVBA
in reply to: kasperwuyts

you could try and set

Application.Visible = False

before starting the plotting labour, and then setting back

Application.Visible = True

 after it's done

this should be effective

 

Message 6 of 9
RICVBA
in reply to: RICVBA

As for my latest suggestion I must say that it could not work since setting Application's Visible property to False could result in an error when trying to zoom.
Just try and watch what happens.
Message 7 of 9
rohit.pal
in reply to: RICVBA

Hi RICVBA, what piece of code will I need to input to save the file on the plotpreview with same name as file name in pdf format. Do you mind writing it?

Message 8 of 9
ebechen28ZBM
in reply to: kasperwuyts

"Above answer are not what I want,because (1)I want to us acWindow an (2)I don't want to get point by hand since I already get those by VBA"
If you think as I did,try my answer,it work for me.

=============================================

Edit  TARGET system 
https://knowledge.autodesk.com/support/autocad/troubleshooting/caas/sfdcarticles/sfdcarticles/Plot-o...

Message 9 of 9
ebechen28ZBM
in reply to: ebechen28ZBM

I didn't find a way that using VBA to edit DVIEW (which controls TARGET system),so  I use SendCommad

 

 

ThisDrawing.SendCommand "DVIEW" & vbCr & "ALL" & vbCr & vbCr & "POINT" & vbCr & "0,0,0" & vbCr & "0,0,1" & vbCr & vbCr

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost