AutoCAD VBA acadPViewport unpredictable behaviour when setting standardscale - vba

I have a VBA script that imports a layout into an exsting drawing, its a paperspace layout and contains one acadPViewport to view the model with.
I need to set a sensible default view, the easiest way to do this is to set the viewport to the extents of the model.
I can do this by calling:
VP.standardscale = acVPScaleToFit
'(optional, I've tried adding these to no effect)
VP.update
currentDocument.Regen
I've experimented and this code call. If I find the viewport in the immediate window, while not running any macros or routines, by referencing:
ThisDrawing.ActiveLayout.block(1).standardscale = acvpscaletofit
it has the desired effect of calling ZoomExtents within the pViewport (as far as I can tell it recenters and recalculates the extents, which is what I'm looking for).
When I run exactly the same code inside my main code it has no effect.
Any ideas appreciated.

The answer, it turns out, is that many features of AutoCAD won't work if the main application is off-screen, hidden, minimised or was at file load.

Related

Manipulation events not triggering on Templated Control [UWP]

I am trying to implement a custom control (Templated Control) for a UWP application for transforming shapes (mostly Rectangle types). Custom control will be implemented in a UWP class library and reference to the main project. What I want to achieve is draw the custom control around another basic shape (eg: Rectangle) and transform the shape according to the manipulations done on the custom control.
I am trying to implement the control with manipulation events (ManipulationDelta, ManipulationCompleted).
I was able to achieve a similar behavior using pointer related events(PointerPressed, PointerMoved, PointerReleased) but it is not very smooth & I want to integrate this control with other applications easily.
Please find the sample source code here.
When I try to move the control the manipulation events are not firing, and I cannot figure out the reason.
I started to work on UWP applications recently and any help on this matter is highly appreciated.
In your scenario, there are several removing codes in PointPressed event, such as “RootCanvas.Children.Remove()”. When you move the control, the PointPressed event is triggered, the previous generated rectangle named resizableRectV2 is deleted. So the resizableRectV2.ManipulationCompleted event will not be triggered.
In addition, I suggest that you don’t create two completely overlapping rectangles, which makes you confused.
Update:
SpeakerView.xaml.cs:
RootCanvas.Children.Remove(RootCanvas.Children.Where(x => x.GetType() == typeof(ResizableRectangle)).FirstOrDefault());
I mean that you could delete the above code in OnPointerPressed event.

Unding Macro actions made during a SlideShow

I want to ask about something, that can probably get pretty complex. I'm working on an interactive presentation with some game elements (stuff that use variables, a timer, score, etc.) and I've noticed that any changes a macro makes (changing the string in a text box, disabling certain shapes) when you run a slide show remain after the slide show has finished. Given that the presentation and the games therein are made to be played multiple times, I would like to avoid having the user click "Undo" a million times or closing and opening the presentation again. I am not sure how to go about this, but I've had a few ideas:
The first one was to track every change that's being made, while the game is running and then have a macro use the "Undo" command the required number of times, once the slideshow is stopped. Creating an Event Handler however proved to be rather complicated. I'm not that well versed in VBA and reading how many declarations, classes and whatnot have to be made, the fact that I cannot find in the reference what the Event for simply ending the slideshow is (that is, when the user presses Esc, not when the last slide has been reached) not to mention the fact that it's very easy to make a mistake that can render all of that code useless, makes me think this is needlessly complicated just for a single event.
Another idea was to set the initial values of the properties that are to be changed during the game, along with the needed variables at the start of the game, so that no matter what changes are made in the presentation, the values will always be reset when running it, although that would make it tedious to tweak things and make big changes to the game, when needed.
Can you give me some suggestions on how I should go about this problem? Which method would be better? Is there some way to make it so that nothing a macro does during a slide show makes actual changes to the presentation itself? I'd very much like to hear your thoughts.
Thanks!

Excel UserForm displays at the wrong size

I'm having a very strange issue with Excel UserForms; when I display a form by clicking a command button in my worksheet, the size of the form warps significantly, making it essentially unusable. The below images illustrate this.
Form before size warping (intended size)
Form after size warping
I work with a multiple screen setup, and this sizing issue only occurred at first when just using my laptop without the additional displays; however, it has now started occurring even with my usual setup. Furthermore, in some cases, the warping compounds with each subsequent form initialization. I've included example images of this below.
Form before warping (intended size)
Form after warping (first iteration)
Compounded warping (second iteration)
Further compounded warping (third iteration)
I've tried setting the height and width properties manually, both through the properties window and through the Userform_Initialize() event, but still end up with strange results. In the properties window, the values I enter for height and width are automatically changed after I enter them, usually resulting in undesirable aspect ratios, and a similar thing happens when I try to resize with VBA. I don't think the code is the issue, as I'm simply setting the .Height and .Width properties so there isn't much room for error.
I've done relatively extensive research and haven't been able to find any information about this issue. I'm using Excel 2016; any help would be appreciated!
I think your issue might be related to mine here.
#Lance Phillips: the option you are referring to (image below found on the web) is missing on my side with Excel 2016 32-bit Windows 10 64-bit. I have no idea why. Even with an extra monitor connected.
Edit: apparently this is a new feature from Office build 9330.1000, see here.
This is a new issue that is occurring in Excel. I have seen it my applications too. In Excel General Options, set to "optimize for compatibility" and the issue should go away.
Other users may not know to set the compatibility mode. If the spreadsheet will be shared with multiple users, use this code to set the correct form size every time it is opened.
Private Sub UserForm_Initialize()
'
' Initialize frm
' (This runs everytime the form is opened)
' frm is the form name
'
' Reset the size
With frm
' Set the form size
Height = {enter desired form height}
Width = {enter desired form width}
End With
End Sub
Check your magnification settings in Windows (Ease of Access). It completely threw my forms sizes. Some were large, others small. Font sizes were as your examples. When a form was created, it inherited the Windows magnification.

Any workarounds for using a RefEdit control inside a Frame control when designing a UserForm in VBA?

I tried to emulate the UserForm design in Data>DataAnalysis>Regression as below, but got very strange errors, usually Excel just crashes. After some googling, it seems the error is because I put RefEdit control inside the frame control. I then deleted the frames and everything went well.
But I have to say having frames makes the interface pretty clear, for instance, it hels separate my input and output options. I wonder how Excel skips this bug and if there is any workarounds in my case.

Excel Button Growing

I'm working on a workbook in Excel 2010 that someone else created (I don't know which version they were using) with a button in it that invokes a macro. There are a lot of macros defined, so I'm right-clicking on it to find out which one it calls, but the context menu doesn't appear. Instead, when I click off, the button gets larger. I can make this happen as many times in a row as I'd like. There is another button the same worksheet that has the same context menu problem, but instead of growing, the text shrinks each time. There is another button that functions normally when I do this.
Growing buttons in Excel is a fairly common issue, with several theories about why this happens, including the use of multiple monitors or using proportional fonts. I have yet to see a definitive answer about this, but there are several workarounds that may work for you.
Delete and re-create the buttons.
Programmatically set the height and width of the buttons when the workbook is opened and when a button is clicked.
Select the button with another object or two on the sheet and group them.
Don't use them at all.
My personal choice is #4. As an alternative to buttons, I either use hyperlinks or shapes with macros assigned to them.
I think you want to enter "Design Mode" in the work book:
You should be able to right-click on the button to see what it does after that.
I have this same issue. I have two Excel workbooks with similar buttons on each. This only happens on one of them, but it happens every time I open that file.
I have found a sort of work-around. I open a blank Excel document, then I open the affected one and the buttons do not change size any more. When I open the second one, I have to drag it into the window with the already-open file. If I double-click on it, it opens in a new window and the problem remains.
I have the same issue sometimes. In my case, I could replicate it 100% on one file but it was inconsistent on an virtually identical file. I also found the size error wasn't permanent -- I could save and reopen the file to restore the button's appearance. I could also create a new window and then discard the damaged window.
For me, the button resized when I accessed the sheet's HPageBreaks collection. I was able to avoid the problem by temporarily changing the window view as follows:
ActiveWindow.View = xlPageBreakPreview
' do pagination stuff using HPageBreaks
ActiveWindow.View = xlNormalView