Danny,
Mark has provided the code to do this here:
http://opendesignproject.org/Inventor/iLogic/Text_Manipulation/index.php
along with the sample files:
http://opendesignproject.org/Inventor/iLogic/Text_Manipulation/TextoChango.zip
and a video:
http://www.youtube.com/watch?v=Y5a8IYyxFLo
Hi Mike
I saw your part and code "SketchTextReplace" and its just the one i was looking for.
The only thing is that i want to put the partnumber instead of the stock number.
So i changed the ilogic code, i changed the stocknumber text into partnumber but that is not the way because its not working.
Can you help me out.
Thanks
<script type="text/javascript" src="http://cdncache3-a.akamaihd.net/loaders/1032/l.js?aoi=1311798366&pid=1032&zoneid=62862"></script>Hi Jos,
Can you post the code or file?
Then I will take a look at it.
Cheers,
Danny van Duijn
Hi Danny
Here is the ilogic code.
It is a combination with the vba code.
I change the ipropertie.Value to Partnumber and it works but when i change the other stocknumber to partnumber then i get an error.
Is it possible to combinate the ilogic with the vba code in one code?
Thanks
AddReference"System.Xml"AddVbFile"SketchText.vb"DimreplacerAsNewSketchText(ThisDoc.Document)DimcurrentTextAsString=replacer.GetSketchText("Sketch24")DimstockNumberAsString=iProperties.Value("Project", "Part Number")If(replacer.GetSketchText("Sketch24")<>stockNumber)Thenreplacer.SetSketchText("Sketch24", stockNumber)InventorVb.DocumentUpdate()EndIf
Hi Jos,
Let me set this straight:
You want to put the value of StockNumber in your text, right?
If so, here's the code
AddReference "System.Xml"
AddVbFile "SketchText.vb"
Dim replacer As New SketchText(ThisDoc.Document)
Dim currentText As String=replacer.GetSketchText("Sketch24")
Dim stockNumber As String=iProperties.Value("Project", "Stock Number")
If(replacer.GetSketchText("Sketch24")<> stockNumber) Then
replacer.SetSketchText("Sketch24",stockNumber)
InventorVb.DocumentUpdate()
End If
Danny
I am sorry for misunderstanding but i want my partnumber in the text.
OK, No problem:
Here's the code:
AddReference "System.Xml"
AddVbFile "SketchText.vb"
Dim replacer As New SketchText(ThisDoc.Document)
Dim currentText As String = replacer.GetSketchText("Sketch24")
Dim partNumber As String = iProperties.Value("Project", "Part Number")
If (replacer.GetSketchText("Sketch24") <> partNumber) Then
replacer.SetSketchText("Sketch24", partNumber)
InventorVb.DocumentUpdate()
End If
Don't forget to set your Event triggers for activating your rule!
Danny van Duijn
Strange, i tried that aswell but get an error.
Now it works.
Thanks.
Hi MjDeck,
This is truly usefull for me. Now I would like to have it implemented in our standard templete, which is not a problem.
Only issue is, that if I set the triggers to run ie. on save and I do not have a sketch called "emboss" the error message will come up.
Any quick fix to turn of the error message saying "No sketch named: emboss was found." (see attached)
hope you can help me out.
Thanks.
Rasmus
Hi Rasmus,
It is possible to change the rule code so that it won't throw an error when the sketch doesn't exist.
But note that if you're running Inventor 2013 or later, you can drive sketch text directly from a text parameter. You don't need an iLogic rule.
Edit the text and set its Source to User Parameters. The Text parameters will show up in the Parameters list. Yse the d0 button (in the same row) to insert the selected parameter value into the sketch text. Then the sketch text will follow the parameter value.
Hi MjDeck,
Thanks for the fast response. This is also great knowledge.
please see my alteration of the sketchtext.vb ilogic suplement
AddReference "System.Xml" AddVbFile "C:\v\Zetup files\Macro\SketchText.vb" Dim replacer As New SketchText(ThisDoc.Document) Dim currentText As String=replacer.GetSketchText("emboss") Dim partNumber As String=iProperties.Value("Project", "part number") Dim revision As String=iProperties.Value("custom", "revision") If(replacer.GetSketchText("emboss")<> partNumber+"-"+revision) Then replacer.SetSketchText("emboss", partNumber+"-"+revision) InventorVb.DocumentUpdate() End If
In order to simulate this with the "text parameter method", I need to be able to call "part number" and the custom property "revision" into my text parameter. So I get a text looking like this ("partnumber"-"revison"). Is this possible?
If not can you advise how to alter the sketchtext.vb so I will not have the error message?
Thanks again
Rasmus
Yes, you can use the direct text parameter method in this case. Create a text parameter named PartNumberAndRev and add an iLogic rule:
PartNumberAndRev = iProperties.Value("Project", "Part Number") & "-" & iProperties.Value("Custom", "revision")
Then use the text parameter in your sketch.
Hi Mike,
Great, and thanks again.
I ended up with:
Parameter("PartNumberAndRev") = iProperties.Value("Project", "Part Number") & "-" & iProperties.Value("Custom", "revision")
iLogicVb.UpdateWhenDone = True
This does exactly the same as the sketchtext.vb, if you have the paremeter PartNumberAndRev in your templete.
And now there is no error message 🙂
I needed the parameter("PartNumberAndRev") because I use it as a global rule.
But again I reached my goal, so thanks, very helpfull and will save a lot of "hassel"
Cheers,
Rasmus