Continue to Site

Welcome to MCAD Central

Join our MCAD Central community forums, the largest resource for MCAD (Mechanical Computer-Aided Design) professionals, including files, forums, jobs, articles, calendar, and more.

J-Link Action Listener Problem

conrat

New member
Hi there,



I am having a little trouble getting an action listener to fire when I
regenerate a specfic model. From what I understand, to implement
an action listener, you create a new instance, then write new methods
to handle the event.



The sample I am listing below is a test I have been working on, to
ensure the events are firing correctly. The problem is, I get
none of the message boxes in the OnBeforeRegen() or OnAfterRegen()
override methods. Can someone take a look at the code and see
where I am going wrong?



The way I need this to work is, a user opens the assembly
"asm_retainers" and before and after the assembly is regenerated, I
should get a pop up box letting me know I am in that method.



One thing I am not sure about (which I think is why this isn't working)
is how to let the new method know which solid to look for.
Although I create a new solid, it is not linked to the new method, at
least as far as I can tell. However, I am not sure how to connect
the two.



Thanks in advance,


Jim



See below:



note: The AlertBox class is a simple little class to display a pop up box.



Begin StartRetainers.java

--------------------



import com.ptc.cipjava.*;<br style="color: rgb(0, 0, 255);">
import com.ptc.pfc.pfcSession.*;<br style="color: rgb(0, 0, 255);">
import com.ptc.pfc.pfcGlobal.*;<br style="color: rgb(0, 0, 255);">
import com.ptc.pfc.pfcModel.*;<br style="color: rgb(0, 0, 255);">
import com.ptc.pfc.pfcSolid.*;<br style="color: rgb(0, 0, 255);">
import com.ptc.pfc.pfcModelItem.*;<br style="color: rgb(0, 0, 255);">
<br style="color: rgb(0, 0, 255);">
public class StartRetainers{<br style="color: rgb(0, 0, 255);">
private static Session curSession=null;<br style="color: rgb(0, 0, 255);">
<br style="color: rgb(0, 0, 255);">
public static void start(){<br style="color: rgb(0, 0, 255);">
new AlertBox("Started", "Started");<br style="color: rgb(0, 0, 255);">
try{<br style="color: rgb(0, 0, 255);">
curSession = pfcGlobal.GetProESession();<br style="color: rgb(0, 0, 255);">
}<br style="color: rgb(0, 0, 255);">
<br style="color: rgb(0, 0, 255);">
catch (jxthrowable x){<br style="color: rgb(0, 0, 255);">
new AlertBox("Something went wrong", "My Title");<br style="color: rgb(0, 0, 255);">
}<br style="color: rgb(0, 0, 255);">
<br style="color: rgb(0, 0, 255);">
try{<br style="color: rgb(0, 0, 255);">
String myModelStr = "asm_retainers";<br style="color: rgb(0, 0, 255);">
Solid myPart = (Solid)curSession.GetModel(myModelStr, ModelType.MDL_ASSEMBLY);<br style="color: rgb(0, 0, 255);">
curSession.AddActionListener(new SolidActionListener());<br style="color: rgb(0, 0, 255);">
<br style="color: rgb(0, 0, 255);">
} catch(jxthrowable x){<br style="color: rgb(0, 0, 255);">
new AlertBox(x.toString(), "jxthrowable");<br style="color: rgb(0, 0, 255);">
}<br style="color: rgb(0, 0, 255);">
return;<br style="color: rgb(0, 0, 255);">
<br style="color: rgb(0, 0, 255);">
}<br style="color: rgb(0, 0, 255);">
<br style="color: rgb(0, 0, 255);">
public static void stop(){<br style="color: rgb(0, 0, 255);">
// new AlertBox("Stop", "Stop");<br style="color: rgb(0, 0, 255);">
}<br style="color: rgb(0, 0, 255);">
}



------------------------------

End StartRetainers.java



Begin SolidActionListener.java

--------------------------



import com.ptc.cipjava.*;<br style="color: rgb(0, 0, 255);">
import com.ptc.pfc.pfcSession.*;<br style="color: rgb(0, 0, 255);">
import com.ptc.pfc.pfcGlobal.*;<br style="color: rgb(0, 0, 255);">
import com.ptc.pfc.pfcSolid.*;<br style="color: rgb(0, 0, 255);">
import com.ptc.pfc.pfcModelItem.*;<br style="color: rgb(0, 0, 255);">
<br style="color: rgb(0, 0, 255);">
public class SolidActionListener extends DefaultSolidActionListener {<br style="color: rgb(0, 0, 255);">
<br style="color: rgb(0, 0, 255);">
public void OnAfterRegen(Solid myPart) throws jxthrowable {<br style="color: rgb(0, 0, 255);">
new AlertBox("I am In OnAfterRegen", "My Title");<br style="color: rgb(0, 0, 255);">
}<br style="color: rgb(0, 0, 255);">
<br style="color: rgb(0, 0, 255);">
public void OnBeforeRegen(Solid myPart) throws jxthrowable {<br style="color: rgb(0, 0, 255);">
new AlertBox("I am In OnBeforeRegen", "My Title");<br style="color: rgb(0, 0, 255);">
}<br style="color: rgb(0, 0, 255);">
}<br style="color: rgb(0, 0, 255);">


---------------------------------

End SolidActionListener.java



Begin AlertBox.java

---------------------------------



import java.awt.*;<br style="color: rgb(0, 0, 255);">
import javax.swing.*;<br style="color: rgb(0, 0, 255);">
<br style="color: rgb(0, 0, 255);">
import com.ptc.pfc.pfcWindow.*;<br style="color: rgb(0, 0, 255);">
<br style="color: rgb(0, 0, 255);">
public class AlertBox {<br style="color: rgb(0, 0, 255);">
public AlertBox(String myContent, String myTitle) {<br style="color: rgb(0, 0, 255);">
Frame myFrame = new Frame(); //Create a new Frame object.<br style="color: rgb(0, 0, 255);">
JOptionPane.showMessageDialog( myFrame, myContent,<br style="color: rgb(0, 0, 255);">
myTitle, JOptionPane.INFORMATION_MESSAGE );<br style="color: rgb(0, 0, 255);">
myFrame.setVisible(false); <br style="color: rgb(0, 0, 255);">
} <br style="color: rgb(0, 0, 255);">
}



---------------------------

End AlertBox.java
 

Sponsor

Articles From 3DCAD World

Back
Top