Insert Drawing Sketched Symbol Behind DrawingView

Insert Drawing Sketched Symbol Behind DrawingView

Matthew_Policelli
Advocate Advocate
1,098 Views
3 Replies
Message 1 of 4

Insert Drawing Sketched Symbol Behind DrawingView

Matthew_Policelli
Advocate
Advocate

I have created an iLogic to make a symbol legend on some of our drawings.

 

In doing so I have run into some issues:

1. Sometimes some of the symbols are placed in the bounds of a drawing view. If I move the drawing view, the symbols will move with the view, and the legend will be messed up. I can get around this by moving the drawing view, running the iLogic, and then moving the view back into place, but is there a way to place the symbol (with iLogic) directly on the sheet such that it won't move with a nearby drawing view?

 

2. Is there a way to determine the bounds of a sketched symbol so that the placement offsets can be dynamically calculated based on the size of the previous symbol placed? I know that this was not possible in 2013, but I wonder if that is still the case. Sometimes a symbol in the legend will be larger than others, and while I can make manual adjustments at the end, it would be nice if there was a way to determine the symbol bounds and place the following symbol accordingly.

0 Likes
Accepted solutions (1)
1,099 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Matthew_Policelli.  The SketchedSymbol moving with a DrawingView or not depends on whether or not its Leader (actually the leader's RootNode, and its AttachedEntity) was placed with a GeometryIntent which references some aspect of the DrawingView.  All SketchedSymbols have a leader, but it may not always be visible, no matter which method you used to place it (Add or AddWithLeader).  That is actually an old tip for how to get a text note on your drawing to move with a view...simply use a leader note, and attach the leader to something in a view, then turn visibility of the leader off.

As for the bounding box of the SketchedSymbol...there still is no such thing in 2024, so we can only get its geometry from its 'Definition' Sketch, get its bounding box size, then use the SketchedSymbol.Scale to determine the size of the placed instance.  Determining where the bounding box of that placed instance is in relationship to other things on the drawing sheet, has to do with the SketchedSymbol.TransformationSketchedSymbol.Position, and where that position is in relation to its bounds, which can be very tricky to figure out.  When you create a SketchedSymbolDefinition, you can specify its insertion point (the point where your cursor/pointer will be in relation to its geometry when placing it).  I would suggest figuring out that insertion point's position, in relation to its 'bounds' ahead of time, either manually, or by code, then maybe create a new AttributeSet within that SketchedSymbolDefinition.AttributeSets, and storing that data in one or more Attribute objects within.  Then you can use that data, along with the position, transformation, and scale to determine where the bounds of the placed sketch symbol are in relation to other stuff in the drawing.  But that's probably a lot more complicated than you were expecting.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

Matthew_Policelli
Advocate
Advocate

Update for those who may have similar problems in the future:

 

I haven't had time to dig into adding code to get the bounds of a sketch symbol yet.

 

For placing the symbol on the sheet and preventing it from moving around with a drawing view, I used the following code to determine if the point where the symbol is being added at is within a view boundary, and if it was, the symbol would be added off of the sheet and then moved to the final point. This could also be modified to do the reverse and add a symbol that is not within a view boundary but moves with the view.

 

The key here is that when the symbol is placed "add" the leader point is where it was initially placed, so when moving it, if that leader is not within a view bounds it will not move with the view.

 

The first snippet shows how I determine if the point will be within a view boundary and places it outside the page and moves it if it will be.

 

Dim placementLoc As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(-100, 100)	'place symbol off of sheet initially, then move to final location to prevent it being tied to drawing view			

If oSheet.DrawingViews.Cast(Of DrawingView).Any(Function(f As DrawingView) PointInDrawingView(f, oInsPoint))
				Logger.Info("have to place " & sym.Name & " around drawing view")
				AddedSym = oSheet.SketchedSymbols.Add(sym, placementLoc, 0, kScale)
				AddedSym.Position = oInsPoint
			Else
				AddedSym = oSheet.SketchedSymbols.Add(sym, oInsPoint, 0, kScale)
			End If

 

And here is the function called to check if point is within view bounds:

''' <summary>
	''' Determine if a point is within the bounds of a drawing view, with 1" margin to catch any borderline cases.
	''' </summary>
	''' <param name="dv">Drawing View to test bounds</param>
	''' <param name="testpt">point to test for location</param>
	''' <returns></returns>
	Private Function PointInDrawingView(dv As DrawingView, testpt As Point2d) As Boolean
	
		Dim isWithinX As Boolean = testpt.X >= dv.Left - 1 AndAlso testpt.X <= dv.Left + dv.Width + 1
		Dim isWithinY As Boolean = testpt.Y <= dv.Top + 1 AndAlso testpt.Y >= dv.Top - dv.Height - 1

		Return isWithinX AndAlso isWithinY

	End Function

 

Message 4 of 4

WCrihfield
Mentor
Mentor

Nice solution @Matthew_Policelli.  I had something similar for checking if a point was within the bounds of a drawing view that I used in some iLogic rules, then later transfered it out into an external iLogic rule for use with the AddVbFile reference.  But this version has a dependency on the TransientGeometry Box2d object, which requires a reference to the application to create,  so not quite as clean, but does work.

Public Function InDrawingViewBounds(oDView As Inventor.DrawingView, oP2D As Inventor.Point2d) As Boolean
	If oDView Is Nothing Or oP2D Is Nothing Then Return False
	Dim oBox2d As Box2d = ThisApplication.TransientGeometry.CreateBox2d
	oBox2d.PutBoxData({oDView.Left, (oDView.Top - oDView.Height) }, {(oDView.Left + oDView.Width), oDView.Top })
	Return oBox2d.Contains(oP2D)
End Function

...so to use it in a vb.net setting, I had to declare the 'ThisApplication' variable as Private within that larger utility code.

I think I actually got the idea from the 3D application of determining if a Point object (3D) was within a transient Box object (or OrientedBox), from things like SurfaceBody.RangeBox & SurfaceBody.OrientedMinimumRangeBox.  The Box2d also had that same Contains method, and I like that.  It helped avoid some math & units related stuff in some situations.  Unfortunately, when creating transient geometry using raw numerical values, you also have to keep units in mind, because they all expect 'internal' (database) units, instead of document units.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)