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

ion

  • Thread starter Thread starter gigi.iacu
  • Start date Start date

gigi.iacu

Guest
ilogic macro numeri progressivi: ho creato una regola su ilogic che al click del mouse mi posiziona un numero progressivo. però, a random, esce dalla macro. ne vorrei capire il perchè.


allego programma. si basa su un foglio.idw.
ho creato una nota sugli editor dei testi chiamata premontaggio ( ostyle = odoc.stylesmanager.textstyles.item("premontaggio"))

ho creato una variabile personalizzata chiamata premontaggio che va aprendere il valore attraverso un modulo. sulla macro sotto trovate anche un input box con apice iniziale.

sub main()
'parameter.updateafterchange = true
dim n_premontaggio as integer

dim ointeraction as interactionevents
ointeraction = thisapplication.commandmanager.createinteractionevents

dim omouse as mouseevents
omouse = ointeraction.mouseevents
addhandler omouse.onmouseclick, addressof omouse_onmousedown

ointeraction.start
'parameter("premontaggio") = inputbox("inserire numero premontaggio", "premontaggio", parameter("premontaggio"))

end sub

sub omouse_onmousedown(button as mousebuttonenum, shiftkeys as shiftstateenum, modelposition as point, viewposition as point2d, view as inventor.view)
parameter.updateafterchange = true

dim odrawdoc as drawingdocument
odrawdoc = thisapplication.activedocument

' set a reference to the active sheet.
dim oactivesheet as sheet
oactivesheet = odrawdoc.activesheet

' set a reference to the generalnotes object
dim ogeneralnotes as generalnotes
ogeneralnotes = oactivesheet.drawingnotes.generalnotes

dim otg as transientgeometry
otg = thisapplication.transientgeometry

' create text with simple string as input. since this doesn't use
' any text overrides, it will default to the active text style.
dim stext as string
'messagebox.show(1,1)
dim ogeneralnote as generalnote

' create a set of notes that are numbered and aligned along the left.
dim dycoord as double
dim dxcoord as double

dycoord = modelposition.y
dxcoord = modelposition.x

dim ostyle as textstyle
dim odoc as drawingdocument
odoc = thisapplication.activedocument
ostyle = odoc.stylesmanager.textstyles.item("premontaggio")
'messagebox.show(2,2)
ogeneralnote = ogeneralnotes.addfitted(otg.createpoint2d(dxcoord, dycoord), parameter("premontaggio"), ostyle)

'messagebox.show(3,3)
parameter("premontaggio") = parameter("premontaggio") + 1
'messagebox.show(4,4)
end sub
 
Last edited:
risolto dichiarando le variabili public.

syntaxeditor code snippetpublic module classefl
public ointeraction as interactionevents
public omouse as mouseevents
public odrawdoc as drawingdocument
public oactivesheet as sheet
public ogeneralnotes as generalnotes
public otg as transientgeometry
public stext as string
public ogeneralnote as generalnote
public dycoord as double
public dxcoord as double
public ostyle as textstyle
public odoc as drawingdocument
end module


sub main()
ointeraction = thisapplication.commandmanager.createinteractionevents
omouse = ointeraction.mouseevents
addhandler omouse.onmouseclick, addressof omouse_onmousedown
ointeraction.start

end sub

sub omouse_onmousedown(button as mousebuttonenum, shiftkeys as shiftstateenum, modelposition as point, viewposition as point2d, view as inventor.view)
parameter.updateafterchange = true

odrawdoc = thisapplication.activedocument

' set a reference to the active sheet.

oactivesheet = odrawdoc.activesheet

' set a reference to the generalnotes object

ogeneralnotes = oactivesheet.drawingnotes.generalnotes


otg = thisapplication.transientgeometry

dycoord = modelposition.y
dxcoord = modelposition.x

odoc = thisapplication.activedocument
ostyle = odoc.stylesmanager.textstyles.item("premontaggio")

ogeneralnote = ogeneralnotes.addfitted(otg.createpoint2d(dxcoord, dycoord), parameter("premontaggio"), ostyle)

parameter("premontaggio") = parameter("premontaggio") + 1
end sub
 
ciao % 1,
what is your experience base on the management of ilogics code (base, intermediate, expert)?

I have made some "bests" to the original ilogic code, added a basic error control, removed the use of public variables (in my opinion not necessary) and tested with the latest version of inventor(2024).
Code:
sub main()   
    dim ointeraction as interactionevents = thisapplication.commandmanager.createinteractionevents
    dim omouse as mouseevents = ointeraction.mouseevents
    addhandler omouse.onmouseclick, addressof omouse_onmousedown
    ointeraction.start
end sub

private sub omouse_onmousedown(button as mousebuttonenum, shiftkeys as shiftstateenum, modelposition as point, viewposition as point2d, view as inventor.view)
    try
        odoc = thisapplication.activedocument
        if thisapplication.activedocument.documenttype.equals(documenttypeenum.kdrawingdocumentobject) then
            progressivo = parameter.param("premontaggio")
            
            opoint = thisapplication.transientgeometry.createpoint2d(modelposition.x, modelposition.y)
            
            ostyle = odoc.stylesmanager.textstyles.item(progressivo.name)
            
            call odoc.activesheet.drawingnotes.generalnotes.addfitted(opoint, progressivo.value, ostyle)
            
            parameter.updateafterchange = true
                
            progressivo.value = progressivo.value + 1
        end if
    catch err as system.exception
        messagebox.show(err.message)
    end try
end sub
 
ciao % 1,
what is your experience base on the management of ilogics code (base, intermediate, expert)?

I have made some "bests" to the original ilogic code, added a basic error control, removed the use of public variables (in my opinion not necessary) and tested with the latest version of inventor(2024).
Code:
sub main()  
    dim ointeraction as interactionevents = thisapplication.commandmanager.createinteractionevents
    dim omouse as mouseevents = ointeraction.mouseevents
    addhandler omouse.onmouseclick, addressof omouse_onmousedown
    ointeraction.start
end sub

private sub omouse_onmousedown(button as mousebuttonenum, shiftkeys as shiftstateenum, modelposition as point, viewposition as point2d, view as inventor.view)
    try
        odoc = thisapplication.activedocument
        if thisapplication.activedocument.documenttype.equals(documenttypeenum.kdrawingdocumentobject) then
            progressivo = parameter.param("premontaggio")
           
            opoint = thisapplication.transientgeometry.createpoint2d(modelposition.x, modelposition.y)
           
            ostyle = odoc.stylesmanager.textstyles.item(progressivo.name)
           
            call odoc.activesheet.drawingnotes.generalnotes.addfitted(opoint, progressivo.value, ostyle)
           
            parameter.updateafterchange = true
               
            progressivo.value = progressivo.value + 1
        end if
    catch err as system.exception
        messagebox.show(err.message)
    end try
end sub
Hi, I'd say base. That is how to add an i-logic rule and let it go. I get an error that says it doesn't find the parameter with the name "premontage". from what I understood I have to add it to the style of editors. I replaced pre-assembly in the code with one of the styles already present in my editor. but it doesn't work anyway. Where's my mistake?
 
in the original code the style and parameter have the same name ("preassembly"), in addition to the style the parameter must be present.
with a small change, the parameter can be added with rule execution.
 

Forum statistics

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

Members online

No members online now.
Back
Top