• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

estrudere nome file in a crypt

  • Thread starter Thread starter Ivantecnico
  • Start date Start date

Ivantecnico

Guest
good day to all, I would like to know if there is a method that allows me to import into a sketch of an ipt the name of the file. or its "number part".
 

Attachments

  • nome file in ipt.webp
    nome file in ipt.webp
    34.1 KB · Views: 11
I do not believe directly but with an ilogic rule.take a look at the attached file.( e' possibile che non si possa allegare un file ipt in questo forum?!)

allora crea questo rule:

addreference "system.web"
imports system.web

sub main()
doc = thisdoc.document

sketchtext = iproperties.value("project", "part number")

dim strings as new generic.list(of string)
strings.add(sketchtext) 'string parameter holding text i want to push to the sketch

setsketchtext("pn text", strings)
ilogicvb.updatewhendone = true


end sub

private doc as document

public sub setsketchtext(byval sketchname as string, byval strings as generic.list(of string))
dim sketch as planarsketch = findsketch(sketchname)

for each textb as textbox in sketch.textboxes
' diagnostics.trace.writeline("-- formatted text = " & textb.formattedtext)
dim newformattedtext as string = replacementformattedtext(textb.formattedtext, strings)
textb.formattedtext = newformattedtext
return
next
end sub

public function replacementformattedtext(byval formattedtext as string, byval strings as generic.list(of string)) as string
dim textlength as integer = formattedtext.length
dim k_gt as integer = formattedtext.indexof(">"c)
if (textlength < 4 orelse k_gt < 0) then
return strings(0) ' no formatting
end if

dim newformattedtext as string = string.empty
dim stringsindex as integer = 0
dim k_start as integer = 0
do
k_gt = formattedtext.indexof(">"c, k_start)
if (k_gt > 0) then
newformattedtext += formattedtext.substring(k_start, k_gt - k_start + 1)
dim k_lt as integer = formattedtext.indexof("<"c, k_gt + 1)
if (k_lt > k_gt + 1) then
if (stringsindex < strings.count) then
newformattedtext += httputility.htmlencode(strings(stringsindex))
stringsindex += 1
end if
end if
k_start = k_lt
end if
loop until k_gt < 0 orelse k_start < 0
return newformattedtext
end function


public function findsketch(byval sketchname as string) as inventor.planarsketch
dim sketches as inventor.planarsketches = nothing
dim opartdoc as inventor.partdocument
dim oassemdoc as inventor.assemblydocument
if (doc.documenttype = inventor.documenttypeenum.kpartdocumentobject) then
opartdoc = doc
sketches = opartdoc.componentdefinition.sketches
elseif (doc.documenttype = inventor.documenttypeenum.kassemblydocumentobject) then
oassemdoc = doc
sketches = oassemdoc.componentdefinition.sketches
end if
if (sketches is nothing) then return nothing

for each sketch as inventor.planarsketch in sketches
if (string.compare(sketch.name, sketchname, true) = 0) then
return sketch
end if
next

throw new argumentexception("no sketch named: " & sketchname & " was found.")


end function


e dai un'occhiata al video.

If you change the pn and save the file, the text changes.
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top