Inventor General

Reply
*Expert Elite*
mrattray
Posts: 2,450
Registered: ‎09-13-2011
Message 11 of 20 (189 Views)

Re: Spell a word on VBA

04-09-2013 09:55 AM in reply to: SeanFarr

Thanks for jumping in with the clarification Dan & Sean.

 

After re-reading the whole thread, I think Sean may be on the right track. Unfortunately, I don't have an immediate solution for him that would work in Inventor's API interface. It would be trivial in VB. If I can get a confirmation from Nikos that this is what he is after, then I'll play around with it later this afternoon after I get some of my work done.

Programming a timer in VBA is something that's been on my wish list for figuring out so, this is indeed a bit interesting. I'm really curious what Nikos is actually trying to accomplish with this in the bigger picture.

Mike (not Matt) Rattray

Active Contributor
nikhunter
Posts: 28
Registered: ‎05-05-2011
Message 12 of 20 (171 Views)

Re: Spell a word on VBA

04-09-2013 01:40 PM in reply to: nikhunter

Ok now i'm sure that all of you, have got the right point on what i'm trying to do

 

Dan, you are exactly on my thoughts....Sean, i have been thinking that way, to use a timer, but i can't find it on VBA....I mean a timer application....

 

mrattray your first command (msgbox....) works very well, and after each reading of a letter,I have the intermediate picture, and a pause with the specific label, which waiting by me to press the button ok and read the second letter....BUT, in this case, i have this "pause label", which waiting my intervention,  that i try to avoid and replace it by an automation application which give me a few seconds to show the right icon and go next ...

 

At the second command (doc.Update) i dont have any indermidiate picture, and i watch directly the finally depiction...

 

Yeah i think that a timer would be the better way to encounter my problem..Between each reading a letter, the program will activate a delay by the timer, that will give me the possibility to see the intermidiate stage...And after passing the specific time that i will have define, the program will reading the next letter and will doing the same work...So i just wanna the right code that doing this delay and on that pause i have the desired image and after passing the time go next...

*Expert Elite*
mrattray
Posts: 2,450
Registered: ‎09-13-2011
Message 13 of 20 (158 Views)

Re: Spell a word on VBA

04-10-2013 04:23 AM in reply to: nikhunter

OK Nikos, I understand what you're after now. I just need to find some time in between jobs that I can figure something out for you.

Mike (not Matt) Rattray

Active Contributor
nikhunter
Posts: 28
Registered: ‎05-05-2011
Message 14 of 20 (146 Views)

Re: Spell a word on VBA

04-10-2013 05:49 AM in reply to: nikhunter

mrattray thanks a lot for your time and i really appreciate that...

 

Take as much time as you want, cause i don't want to disturb you from your occupations...

 

I'll be waiting for your correspondence when you have some new stuff...

*Expert Elite*
mrattray
Posts: 2,450
Registered: ‎09-13-2011
Message 15 of 20 (134 Views)

Re: Spell a word on VBA

04-12-2013 07:00 AM in reply to: nikhunter

Try this out. This should wait 3 seconds between running rules. You can change it to whatever you like. Let me know how it works for you.

 

'Windows call
Private Declare Sub AppSleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
 
Public Sub PauseApp(PauseInSeconds As Long)
    
    Call AppSleep(PauseInSeconds * 1000)
    
End Sub

Public Sub readInput

Dim letter As String
Dim word As String

'Creates a prompt for you to type a word into and assigns it to the variable "word".
word = InputBox("Enter your word.", vbOkCancel, "Your Title")

'Loops through each character in the word you entered.
For i = 1 to Len(word)

'Sets the variable "letter" to each character in "word"
letter = Mid(word, i, 1)
'Fires sub "runRule" and feeds it the variable "letter". This will fire once for every character in "word"
runRule(letter)

'This causes the code to pause for the specified number of seconds
PauseApp 3

Next

End Sub

Private Sub runRule (letter As String)

Dim iLogicAuto As Object
Set iLogicAuto = GetiLogicAddin(ThisApplication)
If (iLogicAuto Is Nothing) Then Exit Sub

Dim doc As Document
Set doc = ThisApplication.ActiveDocument
Dim rule As Object
Dim ruleName As String
Dim i As Integer

Select Case letter
Case Is = "A"
ruleName = "Rule1"
Case Is = "B"
ruleName = "Rule2"
Case Else
  msgbox("Invalid Entry",vbokonly,"Error")
End Select

Set rule = iLogicAuto.GetRule(doc, ruleName)
If (rule Is Nothing) Then
Call MsgBox("No rule named " & ruleName & " was found in the document.")
Exit Sub
End If

i = iLogicAuto.RunRuleDirect(rule)

End Sub

 

Mike (not Matt) Rattray

Active Contributor
nikhunter
Posts: 28
Registered: ‎05-05-2011
Message 16 of 20 (127 Views)

Re: Spell a word on VBA

04-12-2013 08:12 AM in reply to: nikhunter

Ok. Now i have the desirability delay but it still doesn't display to me the indermidiate picture....Propably because i need one more command to do the update except for the pause...

 

 

The only code which have been working until now, was the Msgbox("Press OK to continue.",vbokonly,:Continue?") which  added just before the second End Sub... With this line i have the result i want, but with my intervention.I think that this happen because the specific line cause a break to the programm and it can display the last operation which is to read each Rule...

 

Needed some command that makes update the picture after the "delay function".Something like the "doc.Update" but which works correct....

*Expert Elite*
mrattray
Posts: 2,450
Registered: ‎09-13-2011
Message 17 of 20 (123 Views)

Re: Spell a word on VBA

04-12-2013 08:30 AM in reply to: nikhunter

Try it with both the update method and the pause sub:

 

'Windows call
Private Declare Sub AppSleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
 
Public Sub PauseApp(PauseInSeconds As Long)
    
    Call AppSleep(PauseInSeconds * 1000)
    
End Sub

Public Sub readInput

Dim letter As String
Dim word As String

'Creates a prompt for you to type a word into and assigns it to the variable "word".
word = InputBox("Enter your word.", vbOkCancel, "Your Title")

'Loops through each character in the word you entered.
For i = 1 to Len(word)

'Sets the variable "letter" to each character in "word"
letter = Mid(word, i, 1)
'Fires sub "runRule" and feeds it the variable "letter". This will fire once for every character in "word"
runRule(letter)

Next

End Sub

Private Sub runRule (letter As String)

Dim iLogicAuto As Object
Set iLogicAuto = GetiLogicAddin(ThisApplication)
If (iLogicAuto Is Nothing) Then Exit Sub

Dim doc As Document
Set doc = ThisApplication.ActiveDocument
Dim rule As Object
Dim ruleName As String
Dim i As Integer

Select Case letter
Case Is = "A"
ruleName = "Rule1"
Case Is = "B"
ruleName = "Rule2"
Case Else
  msgbox("Invalid Entry",vbokonly,"Error")
End Select

Set rule = iLogicAuto.GetRule(doc, ruleName)
If (rule Is Nothing) Then
Call MsgBox("No rule named " & ruleName & " was found in the document.")
Exit Sub
End If

i = iLogicAuto.RunRuleDirect(rule)

doc.Update

'This causes the code to pause for the specified number of seconds
PauseApp 3

End Sub

 

If this doesn't work, then I'll need to know what it is you're doing with the rules. That way I can drill directly into the object to update it.

Mike (not Matt) Rattray

Active Contributor
nikhunter
Posts: 28
Registered: ‎05-05-2011
Message 18 of 20 (120 Views)

Re: Spell a word on VBA

04-12-2013 09:15 AM in reply to: nikhunter

Grrrrr....It's still doesn't work....

 

Ok with a Rule i change some degrees on a constraint angle...For instance i have doing a constraint angle at two objects, and when i run first rule (Rule1) the degrees are 90 and when i activate the second (Rule2) the degrees change to 180.....But my work is more complicated...

 

This is the Rule code which i modified according to each angle i want in any Rule....

 

 

Parameter("d248") = 180
Constraint.IsActive("Angle:1") = True

 

Say for example i want to read the word "NIKOS"....When the programm spell the first letter which is "N", the first Rule will be activated and give me the right angle i desire....But i want to see this change....After 3 sec i read the next letter and the second Rule will be activated and give me another angle....And i want to see that again....And this will be continued still the final letter....In our case, i see only the final angle...

*Expert Elite*
mrattray
Posts: 2,450
Registered: ‎09-13-2011
Message 19 of 20 (114 Views)

Re: Spell a word on VBA

04-12-2013 09:24 AM in reply to: nikhunter

These things always take some trial and error. Usually you can put a strong emphasis on the error. 

 

I was under the impression that we were working in a drawing. What happens if you add this line to the beginning of all of your iLogic rules? (You can test it in just a couple if you want to avoid editing a ton of rules for something that might not wok)

 

iLogicVb.UpdateWhenDone = True

 

You might also try this one. Note that the above line will work anywhere in the rule, but the following line needs to be at the end.

 

InventorVb.DocumentUpdate()

 

Are we, by chance, dealing with sub assemblies or iParts/iAssemblies? Is there anything else you can think of with your assembly that might be causing conflicts with Inventor updating properly?

 

Edit in response to your edit: I know what you're trying to achieve, the code snippets that I've been posting over the last few replies should be doing just that. Now we have to do a bit of debugging to figure out why it's not working the way it should.

 

Mike (not Matt) Rattray

Active Contributor
nikhunter
Posts: 28
Registered: ‎05-05-2011
Message 20 of 20 (105 Views)

Re: Spell a word on VBA

04-12-2013 10:09 AM in reply to: nikhunter

YEEEEEEEEAAAAAAAAAAHHHHHHH   :smileytongue:

 

Ιt worked with the second command....I have the desired result

 

 

Man i really appriciate your HELP and i hope to continue that good work......I dont know if i tired you but your patience it was worth it.Thanks again.Really thank you...!!!!!!!!!

 

InventorVb.DocumentUpdate()

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube