CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > Siemens > STAR-CCM+

Run Java macros in Star Ccm+

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 4, 2015, 10:32
Default Run Java macros in Star Ccm+
  #1
New Member
 
Join Date: Nov 2015
Posts: 2
Rep Power: 0
peter parkour is on a distinguished road
Hi!
I recently began programming in Java in order to do some pre-process into Star Ccm+.

The problem I have is when a play in Star Ccm+ a java macro wich calls another macro, Star throws a Instantiation Exception, like if the class was abstract or empty or something.

This is a silly example of what I'm trying with two simple macros (the classpath is correct). The second macro "crearprueba.java" calls the first macro "prueba.java" and set its data member "a" as value for BaseSize.

First class:

public class prueba
{
int a;
public prueba (int b)
{
a=b;
}
}




Second class:

import java.util.*;
import star.resurfacer.*;
import star.common.*;
import star.base.neo.*;
import star.meshing.*;

public class crearprueba extends StarMacro
{
public prueba Pr;
public crearprueba (prueba p)
{
Pr=p;
}

int metodo()
{
return Pr.a;
}

public void execute()
{
prueba paul = new prueba (3);

crearprueba hewson = new crearprueba (paul);

Simulation simulation_0 = getActiveSimulation();

MeshContinuum meshContinuum_0 = simulation_0.getContinuumManager().createContinuum (MeshContinuum.class);

meshContinuum_0.enable(ResurfacerMeshingModel.clas s);

meshContinuum_0.getReferenceValues().get(BaseSize. class).setValue(hewson.metodo());
}
}

Either if I play "prueba.java" or "crearprueba.java" Star Ccm+ throws "java.lan.InstantiationException: prueba/crearprueba"

Any ideas?

Thanks for all the solutions you can provide.
peter parkour is offline   Reply With Quote

Old   November 5, 2015, 07:57
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,686
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
You have to consider that your crearpreuba class is derived from StarMacro, so you can't use your constructer, since this doesn't have any means of creating its super class (StarMacro).

Instead, just do it directly:
Code:
 
public class crearprueba extends StarMacro
{ 
    private Simulation sim_;
    private prueba Pr;

    public void execute()
    {
        sim_ = getActiveSimulationMethod();
        Pr = new prueba (3);
    }
}
To handle this type of situation, I actually find it easier just to pass through differently. For example, we'll call your main class MyMeshVals:
Code:
 
public class MyMeshVals
{ 
    private int val_;

    public void MyMeshVals(int val)
    {
        val_ = val;
    }
 
    public void setSomething(Simulation sim)
    {
        MeshContinuum meshCont = sim.getContinuumManager().createContinuum (MeshContinuum.class);

        meshCont.enable(ResurfacerMeshingModel.clas s);
        meshCont.getReferenceValues().get(BaseSize. class).setValue(val_);
    }
}
And then your caller looks a bit clearer:

Code:
 
public class crearprueba extends StarMacro
{ 
    public void execute()
    {
        Simulation sim = getActiveSimulationMethod();
        MyMeshVals paul = new MyMeshVals(3);
 
        paul.setSomething(sim);
    }
}
olesen is offline   Reply With Quote

Old   November 6, 2015, 02:48
Default
  #3
New Member
 
Join Date: Nov 2015
Posts: 2
Rep Power: 0
peter parkour is on a distinguished road
Hey olesen!
Thanks for your reply and your advices.

I tried your code in Star Ccm+ but Star still does not rcognize "MyMeshVals".
Throws a "cannot find symbol (class MyMeshVals)" message and
I don't know why.

Is it maybe due to not having a .jar file made of the classes in the classpath of Star Ccm+?

The thing is I can't make a .jar file because I can't compile those classes since NetBeans doesn't recognize the lines such as "import star.common.*;"
"import star.base.neo.*;" neither the own methods of Star like " Simulation sim = getActiveSimulation"...
peter parkour is offline   Reply With Quote

Reply

Tags
java macro, star ccm+


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I load Star CCM to Vista? student_58 STAR-CCM+ 0 December 21, 2012 17:29
a java error with installation of Star ccm+ greenfire STAR-CCM+ 1 November 26, 2012 17:15
how to open star ccm 6.04 version file in older versions pritam.edke Siemens 2 June 25, 2012 03:14
Working directory via command line Luiz CFX 4 March 6, 2011 20:02
How to run star design on unix AB Siemens 1 October 1, 2004 13:29


All times are GMT -4. The time now is 07:24.