Declare Features In Vbaeditor

Declare Features In Vbaeditor

Anonymous
Not applicable
641 Views
12 Replies
Message 1 of 13

Declare Features In Vbaeditor

Anonymous
Not applicable

Hi everyone .

I want to write a txt/nc file with vba editor using a part i have already set parameters through i logic.My problem is how can i declare the features so if a feature is suppressed not to write its cordinates.

i also send you the code i am using

Option Explicit

Public Sub ModelParameters()
' Obtain the active document, this assumes
' that a part document is active in Inventor.
Dim oPartDoc As Inventor.PartDocument
Set oPartDoc = ThisApplication.ActiveDocument

' Obtain the Parameters collection
Dim oParams As Parameters
Set oParams = oPartDoc.ComponentDefinition.Parameters
Dim oFeatures As PartFeatures
Set oFeatures = oPartDoc.ComponentDefinition.Features


' Obtain the Model Parameters collection
Dim oModelParams As ModelParameters
Set oModelParams = oParams.ModelParameters
Dim oUserParams As UserParameters
Set oUserParams = oParams.UserParameters
Dim oFeature As PartFeature
Set oFeature = oFeatures.RectangularPatternFeatures


Open "C:\Users\tso\Desktop\test.txt" For Output As #1 'Open file for output

' Program name
Print #1, ";NAME NONAME"
' Dimensions (Length, Width)
Print #1, ";DIM"; oUserParams.Item("Length").Value * 10; oUserParams.Item("Width").Value * 10; "1.5"
' Clamps potition
Print #1, ";PINZE "; "X"; oUserParams.Item("Left_clamp").Value * 10; "Y"; oUserParams.Item("Rigth_clamp").Value * 10
'Tool on the multi-tool and Offset
Print #1, ";TOOL 4000 TONDO 4 MTE6"
Print #1, ";OFFSET X"; oUserParams.Item("Offset_tool_4").Value * 10; "Y0 INDEX"

Print #1, ";CARICO XPIN Y780"
Print #1, ";LAVORAZIONE"
'Hole1
Print #1, ";COLPO X"; oUserParams.Item("Hole1x").Value * 10; "Y"; oUserParams.Item("Hole1y").Value * 10; "C-180"
Print #1, ";LAVORAZIONE"
'Hole2
Print #1, ";COLPO X"; oUserParams.Item("Hole2x").Value * 10; "Y"; oUserParams.Item("Hole2y").Value * 10; "C0"
Print #1, ";LAVORAZIONE"

Print #1, ";COLPO X"; oUserParams.Item("Hole3x").Value * 10; "Y"; oUserParams.Item("Hole3y").Value * 10; "C0"
Print #1, ";LAVORAZIONE"





Close #1 'Close file
End Sub

0 Likes
Accepted solutions (2)
642 Views
12 Replies
Replies (12)
Message 2 of 13

Mark.Lancaster
Consultant
Consultant

@Anonymous 

 

When it comes to Inventor programming needs and question please post over in the Inventor customization forum https://forums.autodesk.com/t5/inventor-customization/bd-p/120 for best results.  I will have the moderator relocate your posting there to best suit your needs.

Mark Lancaster


  &  Autodesk Services MarketPlace Provider


Autodesk Inventor Certified Professional & not an Autodesk Employee


Likes is much appreciated if the information I have shared is helpful to you and/or others


Did this resolve your issue? Please accept it "As a Solution" so others may benefit from it.

Message 3 of 13

marcin_otręba
Advisor
Advisor

try:

 

Public Sub ModelParameters()
' Obtain the active document, this assumes
' that a part document is active in Inventor.
Dim oPartDoc As Inventor.PartDocument
Set oPartDoc = ThisApplication.ActiveDocument

' Obtain the Parameters collection
Dim oParams As parameters
Set oParams = oPartDoc.ComponentDefinition.parameters
Dim oFeatures As PartFeatures
Set oFeatures = oPartDoc.ComponentDefinition.Features


' Obtain the Model Parameters collection
Dim oModelParams As ModelParameters
Set oModelParams = oParams.ModelParameters
Dim oUserParams As UserParameters
Set oUserParams = oParams.UserParameters
Dim oFeature As PartFeature
Open "C:\Users\tso\Desktop\test.txt" For Output As #1 'Open file for output
For Each oFeature In oFeatures
    If oFeature.Suppressed = False Then
' do your stuff
    End If
Next

Close #1 'Close file
End Sub

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 4 of 13

Anonymous
Not applicable

I try this code and it works as it matters the declaration of features.but now it write my stuff over and over again for every feature is active.Is there a way to write something like this.

If oFeature.Suppressed (Specific Feature Name) = False Then

'my stuff'

End if.

thank you very much for your time

 

0 Likes
Message 5 of 13

marcin_otręba
Advisor
Advisor
For Each oFeature In oFeatures
    If oFeature.Suppressed = False Then
' do your stuff
    End If
Next

it handles it.. this will traverse thru all features in your part you can use directly oFeature...

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 6 of 13

Anonymous
Not applicable

the txt i have with this code is this

 

;NAME NONAME
;DIM 2442 212.5 1.5
;PINZE X 330 Y 1560
;TOOL 4000 TONDO 4 MTE6
;OFFSET X 35.499 Y0 INDEX
;CARICO XPIN Y780
;LAVORAZIONE
;COLPO X 45.499 Y 162.5 C-180
;LAVORAZIONE
;COLPO X 29.001 Y 162.5 C0
;LAVORAZIONE
;COLPO X 29.001 Y 45 C0
;LAVORAZIONE
;COLPO X 29.001 Y 45 C0
;LAVORAZIONE
;COLPO X 29.001 Y 45 C0
;LAVORAZIONE
;COLPO X 29.001 Y 45 C0
;LAVORAZIONE
;COLPO X 29.001 Y 45 C0
;LAVORAZIONE
;COLPO X 29.001 Y 45 C0
;LAVORAZIONE
;COLPO X 29.001 Y 45 C0
;LAVORAZIONE
;COLPO X 29.001 Y 45 C0
;LAVORAZIONE
;COLPO X 29.001 Y 45 C0
;LAVORAZIONE
;COLPO X 29.001 Y 45 C0
;LAVORAZIONE
;COLPO X 29.001 Y 45 C0
;LAVORAZIONE
;COLPO X 29.001 Y 45 C0
;LAVORAZIONE
;COLPO X 29.001 Y 45 C0
;LAVORAZIONE
;COLPO X 29.001 Y 45 C0
;LAVORAZIONE

Apparently  the red lines are repeating over an over again for each feature is not suppressed. What i Want is to write only one time this 2 lines only if feature with name "hole3" is not suppressed if it is suppressed i want to go to the next line

0 Likes
Message 7 of 13

marcin_otręba
Advisor
Advisor
Accepted solution

For Each oFeature In oFeatures
If oFeature.Suppressed = False And oFeature.name = "hole3" Then
' do your stuff
End If
Next

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 8 of 13

Anonymous
Not applicable

Thank you very very much . It works Perfectly. Its for my degree for engineer and its very important to finish as soon as possible.Can i ask one more question. in inventor parameters the units are in mm but when i use them in vba editor it turns them in cm so i am forced to multiply wirh 10 as you can see above in the code i post. is there any way to use the parameters in mm??

 

Thanks again

0 Likes
Message 9 of 13

marcin_otręba
Advisor
Advisor

No, it always will be in cm... you can use expression instead of value then you will get exaxt value in mm but  if in paramerer will be equation then you will get an error. So best way is to convert it to mm in your code.

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 10 of 13

Anonymous
Not applicable

thank you again for help and the immediate replies...i will try to finish the code today or tomorrow. if i have problem i will post again...thank you

0 Likes
Message 11 of 13

Anonymous
Not applicable

Hello Again.

i have one more question.

As i say before i try to make through VBA in inventor NC filles for specific Parts we use in our industry.You have already help me and i am in a very good stage with this task.

MY question is this

The cnc machine have tow clamps and every clamp has its safety area if i define this area how can i write to vba tha if the parameter value is in this area dont write it an write it after the line of the reposition.

Is there a way??

0 Likes
Message 12 of 13

marcin_otręba
Advisor
Advisor
Accepted solution

As far as i understand you retrieve X and Y cords right ?

So if you retrieve cords you must check if they are not in clamp area cords.

Something like

If  Clamp minX< featureX<Clamp maxX then
msgbox "Feature in clamp area"
end if

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 13 of 13

Anonymous
Not applicable

Ok...hello again. i did what you said an it works . here is the part from the code

 

For Each oFeature In oFeatures
If oFeature.Suppressed = False And oFeature.Name = "Rectangular Pattern3" And oUserParams.Item("Right_Clamp_ls").Value * 10 > oUserParams.Item("Hole13x").Value * 10 Or oUserParams.Item("Hole13x").Value * 10 > oUserParams.Item("Right_Clamp_rs").Value * 10 Then

'Hole 12
Print #1, ";LAVORAZIONE"
Print #1, ";COLPO X"; oUserParams.Item("Hole12x").Value * 10; "Y"; oUserParams.Item("Hole12y").Value * 10; "C0"

'Hole 13
Print #1, ";LAVORAZIONE"
Print #1, ";COLPO X"; oUserParams.Item("Hole13x").Value * 10; "Y"; oUserParams.Item("Hole13y").Value * 10; "C0"

End If

Next

' reposition of the clamps

Print #1, "Reposition x1250 y2"

 

I dont write for a pop-up message because i dont need it.what i need is this...is there a way the cords from the entire code  wich  they will not be in the txt fille  because they will be between the cords of the clamps safety areas to write them after the line with the reposition  of the clmps

0 Likes