Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Supressing/Removing unused Centremarks in 2D drawing

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
Daan_M
1285 Views, 14 Replies

Supressing/Removing unused Centremarks in 2D drawing

Hi,

 

I'm using iLogic to create a drawing with annotations, this works fine using the workpoints method, simplified example below:

 

 

Dim oWP1 	As WorkPoint = oWorkPoints.Item("WP1name")	'Define workpoints
Dim oWP2 	As WorkPoint = oWorkPoints.Item("WP2name")

Dim oV1Cm1, oV1Cm2 As CenterMark  'Create centermarks on workpoints
	oV1Cm1 = oCMs.AddByWorkFeature(oWP1, oView1) 	
	oV1Cm2 = oCMs.AddByWorkFeature(oWP5, oView1) 	


Dim oV1Int1 As GeometryIntent = oSheet.CreateGeometryIntent(oV1Cm1) 'create geom intents
Dim oV1Int2 As GeometryIntent = oSheet.CreateGeometryIntent(oV1Cm2) 

oPtText_V1_p1 = oTG.CreatePoint2d(oView1.Center.X, (oView1.Top + 1)) 'annotation position for placement

oDimTypeH = DimensionTypeEnum.kHorizontalDimensionType 	'horizontal placement 'annotation orientation

oV1Dim1 = Sheet.DrawingDimensions.GeneralDimensions.AddLinear(oPtText_V1_p1, oV1Int1, oV1Int2, oDimTypeH) 'place annotation

 

 

In some configurations of the assembly specific Parts are supressed, but the iLogic code still creates the Centremarks of the supressed Parts, leaving some floating marks without annotation on my drawing, example below.

 

Daan_M_0-1600422029570.png

 

This is no big problem, but it would be more stylish to not show these in case the part they originate from is supressed, to achieve this i tried the following:

 

use some simple logic to check if the part is supressed, E.g.

 

If part1 = unsupressed 
Dim oWP1 	As WorkPoint = oWorkPoints.Item("WP1name")	'Define workpoints
Dim oWP2 	As WorkPoint = oWorkPoints.Item("WP2name")
else
end if

'rest of the code...

 

 

This failed, which makes sense, because the centermarks cant be created if theres no workpoints to create them from. I would basically have to repeat this 'if statement check' for every single step in creating the annotation, because otherwise the next step will throw an error, this is not ideal...

 

So my question:

Is there a simpeler way of removing these unused centermarks? Any ideas?

 

Looking for some general simple solution i can put in the end of my code if possible:

 

For Each CenterMark in oDrawingDoc
If Centremark = *something*  Then ' *something* = not used as basepoint for creating a linear dimension
CenterMark.Supress
End if
Next

 

 

 

14 REPLIES 14
Message 2 of 15
JhoelForshav
in reply to: Daan_M

Hi @Daan_M 

Since we know that the centermarks attached entity will be of type workpoint, we can use the workpoints healthstatus to see if it has been suppressed. Try this 🙂

 

For Each oCM As Centermark In ActiveSheet.Sheet.Centermarks 'You probably have a variable for your sheet already
If oCM.Attached AndAlso TypeOf (oCM.AttachedEntity) Is WorkPoint _
	AndAlso oCM.AttachedEntity.HealthStatus = HealthStatusEnum.kSuppressedHealth Then oCM.Visible = False
Next

 

 

EDIT:

You're talking about parts being suppressed though so I think maybe we should add to check if its WorkPoint or WorkPointProxy, because I believe the points will in fact be of type WorkPointProxy:

For Each oCM As Centermark In ActiveSheet.Sheet.Centermarks 'You probably have a variable for your sheet already
If oCM.Attached AndAlso (TypeOf (oCM.AttachedEntity) Is WorkPoint Or TypeOf(oCM.AttachedEntity) Is WorkPointProxy) _
	AndAlso oCM.AttachedEntity.HealthStatus = HealthStatusEnum.kSuppressedHealth Then oCM.Visible = False
Next

 

 

 

Message 3 of 15
WCrihfield
in reply to: Daan_M

Here are a couple quick and simple ideas, that come to mind:

> As you create the Centermarks, add the to a collection.  Then as they're being used to create dimensions, add those Centermarks to second collection.  Then loop through the two collections, and whichever ones in the first collection that aren't found in the second collection, you can either delete (oCM.Delete) or hide (oCM.Visible = False).

> Another idea would be to add all the Centermarks to a collection (as in the last idea), then add all the dimensions to another collection as you create them.  Then when they have all been created, loop through each dimension (define each object within as a LinearGeneralDimension, since they are all added using AddLinear), checking their oLinDim.IntentOne.Geometry and oLinDim.IntentTwo.Geometry properties.  Checking to see if each Centermark in the collection is being used.  Any Centermarks (in that collection) that were not used by the end of the Loops can be deleted or hidden.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 15
WCrihfield
in reply to: Daan_M

@Daan_M @JhoelForshav   Actually, I think your method of checking the HealthStatus of the WorkPoint would be more useful at the beginning of the code before the Centermark is created.  Then just don't create the Centermark if the WorkPoint is suppressed.  Also, I think checking its .Attached property, would just confirm it is attached to the WorkPoint it is based on, not necessarily attached to one of the created dimensions.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 15
JhoelForshav
in reply to: WCrihfield

@WCrihfield 

Checking if it's attached is just to make sure it has an attached entity. If it hasn't the code would fail checking the attached entitys type...

 

I just gave an answer to how he can hide the centermarks with a for loop at the end of the code as @Daan_M requested. I don't know how his process will work, maybe he wants to be able to show the centermarks again if the parts gets unsuppressed. Something like:

For Each oCM As Centermark In ActiveSheet.Sheet.Centermarks 'You probably have a variable for your sheet already
	If oCM.Attached AndAlso (TypeOf (oCM.AttachedEntity) Is WorkPoint Or TypeOf (oCM.AttachedEntity) Is WorkPointProxy)
		If oCM.AttachedEntity.HealthStatus = HealthStatusEnum.kSuppressedHealth
			oCM.Visible = False
		Else
			oCM.Visible = True
		End If
	End If

Next
Message 6 of 15
Daan_M
in reply to: JhoelForshav

@JhoelForshav @WCrihfield , Thank you both for the replies and the help thinking towards a solution. i'll need some time to look into it to understand the way it works, ill come back with the outcome later. 

 

Ps; If there is an easy solution it doesn't matter where it is placed in the code, i just assumed it would be most easy to place something at the end, compared to what i was trying to do (make 'if statements'  throughout every step my code). 

 

Addition: The drawing code is ran once, the code to create the 2D is inside a drawing template. The template is opened, the code is executed once, the drawing is saved with a certian name and closed. (this is repeated everytime the assembly gets updated.

 

 

Cheers!

 

 

Message 7 of 15
JhoelForshav
in reply to: JhoelForshav

Just a question @Daan_M 

Are these workpoints you're using on part level or assembly level?

If they're on assembly level they wont be suppressed just because the component they're attached to is. Then we'd have to go through the relationships of the workpoint instead, checking if the occurrence it's constrained to is suppressed...

Message 8 of 15
Daan_M
in reply to: JhoelForshav

The workpoints are inside the Assembly Document. 

 

The more practical solution:

I already check which components are supressed inside the drawingcode for other reasons, so i guess i could use this and manually put some statements at the end of my code pointing out which centermarks to supress. E.g:

 

 

If Flange_Part.Supressed = true
oCM_flange1.visible=false
oCM_flange2.visible=false
end if

 

 

Ofcourse the more 'pretty and general' solution i was aiming for in my initial comment would be to make the centermarks that are not used in creating dimensions invisible, without having to point them out for each part seperately and creating statements

 

Message 9 of 15
JhoelForshav
in reply to: Daan_M

Then I assume the workpoints are constrained to the occurrences of the parts...

Try this at the end of the code. Should work 🙂

For Each oCM As Centermark In ActiveSheet.Sheet.Centermarks 'You probably have a variable for your sheet already
	If oCM.Attached AndAlso TypeOf (oCM.AttachedEntity) Is WorkPoint
		Try
			For Each oConst As AssemblyConstraint In DirectCast(oCM.AttachedEntity, WorkPoint).Dependents.OfType(Of AssemblyConstraint)
				If oConst.AffectedOccurrenceOne.Suppressed Then oCM.Visible = False
			Next
		Catch
		End Try
	End If
Next
Message 10 of 15
Daan_M
in reply to: JhoelForshav

Hi @JhoelForshav, looks like the elegant solution i was trying to find. I haven't yet got it to work, it runs without error, but the Centermarks are still there. To give context, i have 

 

Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Sheet = oDDoc.Sheets.Item(1)

Dim oCMs As Centermarks = oSheet.Centermarks

 

 

And changed your code to fit it:

 

For Each oCMs In oSheet.Centermarks 

	If oCMs.Attached AndAlso TypeOf (oCMs.AttachedEntity) Is WorkPoint
		
			For Each oConst As AssemblyConstraint In DirectCast(oCMs.AttachedEntity, WorkPoint).Dependents.OfType(Of AssemblyConstraint)
				If oConst.AffectedOccurrenceOne.Suppressed Then oCMs.Visible = False
			Next
	End If
Next

 

 

 

 

 

Message 11 of 15
JhoelForshav
in reply to: Daan_M

@Daan_M 

Ok... Could you share a picture of your assembly tree with the parts suppressed so I can see the structure? 🙂

Message 12 of 15
WCrihfield
in reply to: Daan_M

Assuming both sections of code you posted are in the same rule...It looks like you need to create a new variable for a single Centermark object, instead of reusing the variable which represents the whole collection of Centermarks that exist on the sheet.

The variable oCMs is representing all the Centermarks on the oSheet.

You need to create a new variable, similar to the example Jhoel has posted:

Dim oCM As Centermark

then

For Each oCM In oCMs

or

For Each oCM As Centermark In oCMs

Then replace oCMs throughout the rest of that block of code with the new (singular) variable, oCM.

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 13 of 15
JhoelForshav
in reply to: WCrihfield

Well spotted @WCrihfield!

You could just run the code exactly as i posted it @Daan_M to see if it works. But then change it according to @WCrihfield's suggestion to make it look better 🙂

Message 14 of 15
Daan_M
in reply to: JhoelForshav

Edit; Solved

 

 

Message 15 of 15
Daan_M
in reply to: JhoelForshav

@JhoelForshav @WCrihfield Works perfectly, Points for both of you! 

Have a nice weekend

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report