The first thing is to how to create rescale the view to fit into the region of the drawing. What command I should use? Any example?
Get the X and Y coordinates for start and end for the region, so that you get the center point o place the view. Then scale the view using ScaleRatio. And comparing the view bounding box size withe the region size. Keep changing scale until both matches or bounding box is smaller than that region.
I made it for myself of the pieces and rags. It not perfect, but it works.
Maybe it will be useful for someone.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim swView As SldWorks.View
Dim vScaleRatio, vpos, voutline As Variant
Dim bRet As Boolean
Dim x, y As Integer
Dim Part As Object
Dim boolstatus As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swSelMgr = swModel.SelectionManager
Set swView = swSelMgr.GetSelectedObject5(1)
vpos = swView.Position
voutline = swView.GetOutline
x = vpos(0)
y = vpos(1)
vScaleRatio = swView.ScaleRatio
vScaleRatio(0) = 1
swView.ScaleRatio = vScaleRatio
'Do While (voutline(2) - voutline(0)) > 0.2
'If voutline(2) - voutline(0) > 0.2 Then
'vScaleRatio(1) = vScaleRatio(1) + 1
''Debug.Print " voutline(2)-voutline(0) = " & voutline(2) - voutline(0)
'swView.ScaleRatio = vScaleRatio
'bRet = swModel.EditRebuild3: Debug.Assert bRet
'voutline = swView.GetOutline
'Do While (voutline(2) - voutline(0)) < 0.1
'If voutline(2) - voutline(0) < 0.1 Then
'vScaleRatio(1) = vScaleRatio(1) - 1
'vpos(0) = ((voutline(2) - voutline(0)) / 2) + 0.03
'vpos(1) = 0.297 - 0.015 - ((voutline(3) - voutline(1)) / 2)
'swView.Position = vpos
Do While (voutline(2) - voutline(0)) > 0.2
vScaleRatio(1) = vScaleRatio(1) + 1
'Debug.Print " voutline(2)-voutline(0) = " & voutline(2) - voutline(0)
bRet = swModel.EditRebuild3: Debug.Assert bRet
Do While (voutline(2) - voutline(0)) < 0.1
vScaleRatio(1) = 1
vScaleRatio(0) = vScaleRatio(0) + 1
vpos(0) = ((voutline(2) - voutline(0)) / 2) + 0.03
vpos(1) = 0.297 - 0.03 - ((voutline(3) - voutline(1)) / 2)
swView.Position = vpos
'Debug.Print "File = " & swModel.GetPathName
Debug.Print " View = " & swView.Name
'Debug.Print " UseSheetScale = " & CBool(swView.UseSheetScale)
Debug.Print " Scale = " & vScaleRatio(0) & ":" & vScaleRatio(1)
'Debug.Print " = " & swView.ScaleDecimal
Voverrr Mironoff any chance you could offer some insight?
I'm getting the below error.
I am not Macro-Literate, I just pasted your post into a new macro page within SW (removed the extra "sub Main" and "End Sub" that are default in the new macro window|)
Running SW 2016 SP 3.0, win 10 Pro 64-bit
Check the macro references in the VBA editor and make sure "Utilities" library is unchecked.
Deepak Gupta thanks for the reply
Did as insturcted, but I still get the same error I'm afraid. I must be doing something wrong
Tried it again and now get a diffrent error. (did't change anything, just different error (?)) I've stumped myself without even trying
Ok so just realized that drawing file shol dbe active for this macro to do it's thang.
Tried it again an this screenshot below is the error I get now
Well make sure you've a drawing open else we can do a quick screen sharing to see what is going on your machine (PM me if you can do the screens sharing)
Ah, yes. lol, Ok so i tried on the drawing (doy) this time and recieved the different error I posted in the edited comment.
PM sent in case my new error still requires screensharing
You need to have a view selected
where is the facepalm emoji when you need it.
Ok so it worked now obviously.
I hadn'te realized the capability of the particular macro
Now, I just need to find out how to make it
No big deal, Simple stuff
I'm doomed and clueless
Well all of these are possible and the main command you would need are view.GetOutline and view.Position
I'm trying to make a similar but slightly different macro (with no success yet). Will post if I'm able to get that working.
Hello, guys. I see, you already solve some tasks while I was asleep on this side of the Earth.
Nick, you have a great plans for this macro)))
Deepak, does it possible to manually define the boundary box of view wich should be scaled to? I know, it will be against the drawing standarts: iso, din, gost. As result we'll get the views with the scale something like 1:23 or 1:5.6 but there are not so stronger rules at my factory.
If only my macro skills matched the size of my plans
Voverrr Mironoff wrote: Deepak, does it possible to manually define the boundary box of view which should be scaled to?
Voverrr Mironoff wrote:
Deepak, does it possible to manually define the boundary box of view which should be scaled to?
Yes it can be done.
Fingers crossed, it will come together
Have you finished to work on this macro? Which can auto scale the view and same as Rescale And Position View in drive works?
Devas Sheth wrote: Have you finished to work on this macro? Which can auto scale the view and same as Rescale And Position View in drive works?
Devas Sheth wrote:
No I never started any work on that macro.
Thanks sir for your response.
It will be great if you could guide me on this as I need to position drawing with auto scale.
Have you looked at the macro codes by Voverrr in his above post?
Yes sir, but it change the position of the view.
Devas Sheth wrote: Yes sir, but it change the position of the view.
Remove the codes for the position of the view.
Still not works.
Retrieving data ...