Drawing template - sketch disappears

Drawing template - sketch disappears

frankstardelux
Enthusiast Enthusiast
353 Views
2 Replies
Message 1 of 3

Drawing template - sketch disappears

frankstardelux
Enthusiast
Enthusiast

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.

 

frankstardelux_0-1640200857369.png

 

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)

 

0 Likes
354 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor

I think this one has come up before that the template drawing on new document deletes the sketch. Perhaps you can copy over the sketch after you create the drawing? Maybe try out the technique first manually then automate to suit your need. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 3

JelteDeJong
Mentor
Mentor

At my job, I have done something similar. But it seems that you use a sketch to define the place and size of your views. I hardcoded the places and max view sizes in the rule itself. That saves me a used sketch in the template. What i ended up doing was creating a settings file with multiple sheet layouts. And I ask the user which layout he/she wants to use. That would not have been possible with a sketch. So my advice would be don't use the sketch.

 


@frankstardelux  wrote:

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


It's not just you. but there is an explanation for it.

ThisApplication.ActiveDocument returns a Document object. Not a DrawingDocument object. Because a Document object does not have an ActiveSheet property the computer does not know that it can be used until runtime. If you want the autofiller to work than you need to define the document as a DrawingDocument. something like this.

Dim doc As DrawingDocument = ThisDoc.Document
Dim oDrawingViews As DrawingViews = doc.ActiveSheet.DrawingViews

Also, notice that I used ThisDoc.Document instead of ThisApplication.ActiveDocument. Using the active document is not always the document that you would expect. In some cases, you can exploit this difference but usually, it's more save to use ThisDoc.Document. (In my post "Run 'Before Save' Rule Only Once in Assemblies" i show an example of an exploit of this difference.)

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes