Drawing template - sketch disappears
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey guys,
Attached is a drawing which contains a sketch. The weird thing is, when I save this into my Template folder and create a new drawing using it, the sketch isn't there! Any help would be appreciated - and I realise this is kind of niche.
To give a little more background, and potentially help some people out in the future, I'm trying to create a template which is pre populated with a number of views which resize depending on the size of the part. To see how it works, save both attachments and open up the drawing.
The sketch in the attached drawing allows for some easy visualisation of how the space on the sheet will be used and the dimensions in this sketch drive the ilogic, so the template can be tweaked over time by updating this sketch and without any intervention on the ilogic side, run the rule and the views would resize and reposition so that, no matter how big or small the part is, the views occupy a similar amount of space on the sheet. Feel free to drag the views around on the page and change their scales, then head over to the ilogic tab and run "Auto position at Startup". This ilogic is what I would like to run automatically when creating a new drawing but with the sketch missing, the ilogic fails for obvious reasons.
Cheers,
Frank.
Ps. When typing out the following line of code, is it just me or does "ActiveSheet" and "Sketches" not appear in the autofiller?
ThisApplication.ActiveDocument.ActiveSheet.Sketches
Code for future reference
Dim oDrawingViews As DrawingViews = ThisApplication.ActiveDocument.ActiveSheet.DrawingViews
Dim oView As DrawingView = Nothing
Dim oSketch As Sketch
Dim oBasePosition As Point2d = Nothing
oBasePosition = ThisApplication.TransientGeometry.CreatePoint2d()
oSketch = ThisApplication.ActiveDocument.ActiveSheet.Sketches.Item(1)
'Max 2D viewSize - Look for d0 in Sketch1
Dim viewSize As Double = oSketch.DimensionConstraints.Item(1).Parameter.Value
'2D view
oView = oDrawingViews.Item(1)
'Rotate the view so it's wider than it is tall
If oView.Height>oView.Width Then
oView.Rotation = oView.Rotation - (PI / 2)
oDrawingViews.Item(3).ViewOrientationFromBase = True
oDrawingViews.Item(4).ViewOrientationFromBase = True
End If
'The size of the part in mm can be obtained by dividing the current width of the view by it's current scale
Dim partSize As Double = oView.Width / oView.Scale
If partSize > viewSize Then
'use a scale less than 1
oView.Scale = 1 / Ceil((oView.Width / oView.Scale)/viewSize)
Else
'use a scale greater than 1
oView.Scale = Floor(viewSize/(oView.Width / oView.Scale))
End If
'View numbering starts at 1
'Distances are measured in cm
'To refer to the bottom left edge of the view, use: +(oView.Width/2)
'Positions have to be set in pairs, cannot do X or Y on it's own.
oBasePosition.X = oSketch.DimensionConstraints.Item(7).Parameter.Value
oBasePosition.Y = oSketch.DimensionConstraints.Item(8).Parameter.Value
oDrawingViews.Item(1).Position = oBasePosition
oBasePosition.Y = oSketch.DimensionConstraints.Item(10).Parameter.Value
oDrawingViews.Item(3).Position = oBasePosition
oBasePosition.X = oSketch.DimensionConstraints.Item(9).Parameter.Value
oDrawingViews.Item(4).Position = oBasePosition
'ISO view
oView = oDrawingViews.Item(2)
viewSize = oSketch.DimensionConstraints.Item(13).Parameter.Value
partSize = oView.Width / oView.Scale
If partSize > viewSize Then
'use a scale less than 1
oView.Scale = 1 / Ceil((oView.Width / oView.Scale)/viewSize)
Else
'use a scale greater than 1
oView.Scale = Floor(viewSize/(oView.Width / oView.Scale))
End If
oBasePosition.X = oSketch.DimensionConstraints.Item(11).Parameter.Value
oBasePosition.Y = oSketch.DimensionConstraints.Item(12).Parameter.Value
oView.Position = oBasePosition
oBasePosition.Y = oSketch.DimensionConstraints.Item(12).Parameter.Value + oSketch.DimensionConstraints.Item(14).Parameter.Value
oDrawingViews.Item(5).Position = oBasePosition
oDrawingViews.Item(5).Scale = oView.Scale
if oDrawingViews.Item(5).Aligned = False then oDrawingViews.Item(5).Align(oview,kverticalviewalignment)