Change all Hole to new class form 2d drawing with a marco or ilogic code , how ?

Change all Hole to new class form 2d drawing with a marco or ilogic code , how ?

Darkforce_the_ilogic_guy
Advisor Advisor
239 Views
2 Replies
Message 1 of 3

Change all Hole to new class form 2d drawing with a marco or ilogic code , how ?

Darkforce_the_ilogic_guy
Advisor
Advisor

 

we have made a change to special type for treaded holes.  Create by the hole features. normale/beforce is was call 6H. now it just call ". ". I  would like to create an buttom, that When  you have the drawing open and you see that some of the holes have the wrong/old class.  you can hit the Bottom and change all hole feature type "Kallesoe Metric profile" and have the class 6H to class = ". "  how would i do this ?

 

 

bt_1-1647868735011.png

 

sd

 

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

Ralf_Krieg
Advisor
Advisor

Hello

 

Try this one.

Private Sub UpdateThreadClass()

Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument

Dim oRefedDoc As Document
Dim oPartDoc As PartDocument
For Each oRefedDoc In oDrawDoc.AllReferencedDocuments
    If oRefedDoc.DocumentType = kPartDocumentObject Then
        Set oPartDoc = oRefedDoc
        Dim oHoleFeature As HoleFeature
        For Each oHoleFeature In oPartDoc.ComponentDefinition.Features.HoleFeatures
            If oHoleFeature.Tapped = True Then
                Dim oTapInfo As HoleTapInfo
                Set oTapInfo = oHoleFeature.TapInfo
                If oTapInfo.ThreadType = "Kallesoe Metric profile" Then
                    oTapInfo.Class = "."
                End If
            End If
        Next
    End If
Next

End Sub

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor

Hi @Darkforce_the_ilogic_guy.  The iLogic rule I was preparing for you is pretty similar, but just includes the extra check to see if the thread Class is currently set to "6H" or "6h", before attempting to change its Class to ".".  There are several ways you may prefer to get/identify the drawing document, and/or the 'Model' document, so I just kept that part fairly simple.  I don't know if your drawing document is just for the one model, or if there are multiple models, but this code just gets the first model, for simplicity.  I also just assumed that the model would be a Part, due to the threaded hole features, so if your model is not a part, it will not work the way it currently is.  I also threw a couple of updates in there at the end.

Sub Main
	'get the Drawing (one way or another)
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing Document must be active for this code to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisDoc.Document
	'get Model (again, which ever way you want)
	Dim oModel As Document = ThisDoc.ModelDocument
	If oModel Is Nothing Then
		MsgBox("No 'Model' found.  Exiting.", vbCritical, "")
		Exit Sub
	End If
	'I assume it will be a Part because of threaded HoleFeatures
	If oModel.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
		MsgBox("'Model' was not a part. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oPDoc As PartDocument = oModel
	oPDef = oPDoc.ComponentDefinition
	oHFeats = oPDef.Features.HoleFeatures
	For Each oHFeat As HoleFeature In oHFeats
		If Not oHFeat.Tapped Then Continue For
		Dim oHTInfo As HoleTapInfo = oHFeat.TapInfo
		If oHTInfo.ThreadType <> "Kallesoe Metric profile" Then Continue For
		'If oHTInfo.ThreadTypeIdentifier <> "Kallesoe Metric profile" Then Continue For
		If oHTInfo.Class = "6H" Or oHTInfo.Class = "6h" Then
			Try
				oHTInfo.Class = "."
			Catch
				MsgBox("Failed to change thread 'Class' to '.'", vbExclamation, "")
			End Try
		End If
	Next
	oPDoc.Update
	oDDoc.Update
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :bulb: or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)