How can the mesh process be finished by Macro/API?

lance.xi
Enthusiast
Enthusiast

How can the mesh process be finished by Macro/API?

lance.xi
Enthusiast
Enthusiast

We want to automate the whole process for some simple case.

However, the mesh process can not be done by macro or API.

 

Is there any other way?

 

Thanks

0 Likes
Reply
1,663 Views
17 Replies
Replies (17)

bernor_mf
Advisor
Advisor
Accepted solution

Hi,

you could use meshing with macro/API.

 

MeshGenerator Class Reference
See: Synergy API Reference

How to find Moldflow API documentation and reference

 

Code example:

Set MeshGenerator = Synergy.MeshGenerator()
MeshGenerator.EdgeLength 1.31
MeshGenerator.MergeTolerance 0.1
MeshGenerator.Match True
MeshGenerator.Smoothing True
MeshGenerator.ElementReduction False
MeshGenerator.SurfaceOptimization True
MeshGenerator.AutomaticTetraOptimization True
MeshGenerator.TetraRefine True
MeshGenerator.TetraLayers 10
MeshGenerator.TetraLayersForCores 6
MeshGenerator.TetraMaxAR 15
MeshGenerator.UseTetrasOnEdge False
MeshGenerator.MaximumMatchDistance 1E+23
MeshGenerator.MaximumMatchDistanceOption 0
MeshGenerator.RemeshAll False
MeshGenerator.UseActiveLayer False
MeshGenerator.PostMeshActions True
MeshGenerator.MergeCavityRunner True
MeshGenerator.ChordHeightControl True
MeshGenerator.ChordHtAspectRatio False
MeshGenerator.ChordHtProximity False
MeshGenerator.ChordHeight 0.1
MeshGenerator.NurbsMesher 1
MeshGenerator.SourceGeomType "Auto-Detect"
MeshGenerator.ChordAngleSelect False
MeshGenerator.UseAutoSize True
MeshGenerator.CadAutoSizeScale 1
MeshGenerator.CadContactMeshType "Ignore contact"
MeshGenerator.CadSliverRemove False
MeshGenerator.UseFallbacks True
MeshGenerator.Mesher3D "AdvancingLayers"
MeshGenerator.MaxEdgeLengthInThicknessDirection 0
MeshGenerator.ELTTRatio 1.2
MeshGenerator.ELTTRatioAL 0.5
MeshGenerator.MeshComponentType 0
MeshGenerator.IncThkDD True
MeshGenerator.UseGateRef True
MeshGenerator.GateELFactor 20
MeshGenerator.SurfaceEdgeLengthScaleFactor 1
MeshGenerator.MeshCurvesByGEL False
MeshGenerator.EdgeLengthRatioRunner 0.75
MeshGenerator.EdgeLengthRatioCircuits 2.5
MeshGenerator.MaxChordHeightRatioCurv 0.08
MeshGenerator.MinNumElmGates 3
MeshGenerator.MinNumElmBaffleBubblers 3
MeshGenerator.CadMeshGradingFactor 0
MeshGenerator.CoolType 2
MeshGenerator.SaveOptions
Set StudyDoc = Synergy.StudyDoc()
StudyDoc.MeshNow True


To avoid check box when meshing completed use
StudyDoc.MeshNow False

 

 

Hope this helps.

Regards,

Berndt

( If my comments are accepted, provide "Kudos" as appreciation. If your request is answered/resolved, please click the "Accept as Solution" button. Thanks.)

lance.xi
Enthusiast
Enthusiast

Dear Berndt,

 

Thanks for your help.

 

Could you help me again that, how can I set injection locations through API?

 

Thanks!

0 Likes

bernor_mf
Advisor
Advisor

Hi @lance.xi,

Injection location for thermoplastics processes tcodeset reference:


40000 Injection location for thermoplastics processes


This adds injection location to node 2, N2

Set BoundaryConditions = Synergy.BoundaryConditions()
Set Vector = Synergy.CreateVector()
Set EntList = BoundaryConditions.CreateEntityList()
EntList.SelectFromString "N2 "
Vector.SetXYZ 0, 0, 1
Set EntList_1 = BoundaryConditions.CreateNDBC(EntList, Vector, 40000, Nothing)

 Hope this helps.

Regards,

Berndt

( If my comments are accepted, provide "Kudos" as appreciation. If your request is answered/resolved, please click the "Accept as Solution" button. Thanks.)
0 Likes

lance.xi
Enthusiast
Enthusiast

Dear Berndt,

 

Thanks for your reply.

 

Could I set the injection location by absolute X/Y/Z?

 

Or just as what macro can do, can I set the injection location at anywhere without considering the mesh nodes?

 

Thanks!

 

Besides, can you share me some tutorials/examples that I can run a simple simulation fully by API?

 

That is, the API can complete the whole process: mesh->set injection location->set fill type->select material->run simulation->output report?

 

Thanks!

 

 

 

0 Likes

bernor_mf
Advisor
Advisor
Accepted solution

Hi,

first, record your workflow with macro, and review the macro code.

Many times useful to use as a starting point.

 

If you want to be in control, you can create a node by coordinate first, before meshing and it will have N1

Creates a node at a given point

 Set Vector = Synergy.CreateVector()
  Set Modeler = Synergy.Modeler()
  Vector.SetXYZ 10, 100, 0
  Set EntList = Modeler.CreateNodeByXYZ(Vector)

 

See: Synergy API Reference

How to find Moldflow API documentation and reference

 

API scripts examples.

 

From Autodesk University, AU :

CP9844-L: The Autodesk Moldflow Synergy API part 1: An Introduction

CP12451-L: The Autodesk Moldflow Synergy API part 2: Building real world applications

 

Hope this helps.

Regards,

Berndt

 

( If my comments are accepted, provide "Kudos" as appreciation. If your request is answered/resolved, please click the "Accept as Solution" button. Thanks.)
0 Likes

lance.xi
Enthusiast
Enthusiast

Dear Berndt,

 

Thanks very much.

 

With your help and the tutorials, I can set the injection location, mesh and run simulation.

 

However, 1) I do not know how to select the material with API, although there is tutorial about showing the material properties with name and ID; 2) Do not know how to export results to directly to PPT or from .mfr file to PPT.

 

Could you give some instruction?

 

Thanks!

 

I am keeping practis

0 Likes

bernor_mf
Advisor
Advisor
Accepted solution

Hi @lance.xi,

you are welcome. Happy to help. Smiley Happy

 

1) Record a macro when selecting a material. It will return codes needed.

Set MatSel = Synergy.MaterialSelector()
MatSel.Select "DuPont Performance Polymers.21000.udb", "System", 31529, 0

 

So if you use a couple of materials, repeat this operation to get codes.

 

2) .mfr is Moldflow Communicator file

Is a free viewer.

You export model and plots. Plots has to be marked for export, and study saved.

From viewer you cannot export to PPT.

Same advice: record a macro, when marking results for export and save study, to get code.

 

For automated report, you need to read up om this:

Custom reports

 

Hope this helps.

Regards,

Berndt

 

 

( If my comments are accepted, provide "Kudos" as appreciation. If your request is answered/resolved, please click the "Accept as Solution" button. Thanks.)
0 Likes

lance.xi
Enthusiast
Enthusiast

Dear Berndt,

 

Thanks for your advice.

 

Can I open MoldFlow Insight by excel/IE and run the .vbs files through Excel/IE instead of command line?

 

Could you give some suggestions?

 

Thanks!

0 Likes

bernor_mf
Advisor
Advisor
Accepted solution

Hi @lance.xi,

you are welcome.

Happy to help.

 

Yes, you can use Excel and/or IE.

I have used Excel , but neve IE actually.

 

You connect to Synergy as in vbs:

Sub Connect_Moldflow()

'%RunPerInstance
'@ DESCRIPTION
'@ Macro recorded by Synergy
'SetLocale ("en-us")
Dim SynergyGetter, Synergy
On Error Resume Next
Set SynergyGetter = GetObject(CreateObject("WScript.Shell").ExpandEnvironmentStrings("%SAInstance%"))
On Error GoTo 0
If (Not IsEmpty(SynergyGetter)) Then
    Set Synergy = SynergyGetter.GetSASynergy
Else
    Set Synergy = CreateObject("synergy.Synergy")
End If
Synergy.SetUnits "Metric"

End Sub

 

Getting Started with VBA in Excel 2010

(Even if 2010 it is useful information.)

 

Hope this helps.

Regards,

Berndt

 

 

( If my comments are accepted, provide "Kudos" as appreciation. If your request is answered/resolved, please click the "Accept as Solution" button. Thanks.)
0 Likes

lance.xi
Enthusiast
Enthusiast

Dear Berndt,

 

When I tried to control the MoldFlow by excel, I encountered the following problems. Please help:

 

1) When I tried to close the MoldFlow manually after running VBScript code by excel, there is error message like following:

"Error Report-Required Value Missing

An Autodesk product failed to send required value of SERIALNUM......."

 

How to avoid this error?

 

2) When I used the following script to create injection location, the vector does not work. That is, the direction of injection is not perpendicular to the injection surface selected.

Dim Modeler
Dim BoundaryConditions
Dim Vector
Dim EntList
Dim EntList_1
Dim Vector2
Dim X_injection
Dim Y_injection
Dim Z_injection
Dim X_vector
Dim Y_vector
Dim Z_vector

X_injection = Range("XValueofinjection").Value
Y_injection = Range("YValueofinjection").Value
Z_injection = Range("ZValueofinjection").Value
X_vector = Range("XValueofVector").Value
Y_vector = Range("YValueofVector").Value
Z_vector = Range("ZValueofVector").Value

  Set Vector = Synergy.CreateVector()
  Set Modeler = Synergy.Modeler()
  'Vector.SetXYZ 0, 0, 0
  Vector.SetXYZ X_injection, Y_injection, Z_injection
  Set EntList = Modeler.CreateNodeByXYZ(Vector)

Set BoundaryConditions = Synergy.BoundaryConditions()
Set Vector2 = Synergy.CreateVector()
    'Vector2.SetXYZ 0, 0, 1
    Vector2.SetXYZ X_vector, Y_vector, Z_vector
Set EntList_1 = BoundaryConditions.CreateNDBC(EntList, Vector, 40000, Nothing)

 

3) When I used the CustomReport.vbs to generate the report in excel, there are a number of errors reported. One of the error is as following:

"Object required"

The function is as following, while I do not know how to define the "WScript " object.

Function IsSilentArgument()
' Deterimine if the -silent option is specified on the command line
    IsSilentArgument = False
    Dim Args, i
    Set Args = WScript.Arguments
    For i = 0 To Args.Count - 1
        If Args(i) = "-silent" Then
            IsSilentArgument = True
        End If
    Next
End Function

 

 

 

Please help.

 

Thanks

 

0 Likes

bernor_mf
Advisor
Advisor
Accepted solution

Hi @lance.xi

 

1) Moldflow Insight: An Autodesk product failed to send the required value for SERIALNUM

See Autodesk Knowledge Network, AKN, article:

Moldflow Insight: An Autodesk product failed to send the required value for SERIALNUM


2) Injection Location cone, direction

This should work for simulation, no matter direction of Injection Location Cone.
The look of it is then strange, as not normal to surface or even going in surface through thickness.
I have no code of getting normal vector of added node for injection location cone.
Believe this could be a bit complicated in API code.
Maybe mesh model first, with injection location at node.
Find the injection location node, and one of the triangles attached to it.
Then from adjacent triangle, find and get three nodes to calculate a normal vector.

 

3) CustomReport.vbs in to Excel vb

As I understand, you copied CustomReport.vbs in to Excel vb, right?
Copy code to be used from command line to Excel vb will probably create a lot of issues.

Some functions for vbs might not be valid in Excel.
A lot of work to debug, I believe.

I am sorry, but on this I cannot help out.
Maybe you should leave it out from Excel, and run separately afterwards?

 

Hope this helps.

Regards,

Berndt

 

( If my comments are accepted, provide "Kudos" as appreciation. If your request is answered/resolved, please click the "Accept as Solution" button. Thanks.)
0 Likes

lance.xi
Enthusiast
Enthusiast

Dear Berndt,

Thanks for your advice.

 

Another thing, how can the analysis is auto-started after the mesh process completed?

 

At present,  there are three separate .vbs files for mesh->run-analysis->generate-report.

 

How can I adjust whether the mesh/analysis process is completed and auto-start next step?

Thanks!

 

 

0 Likes

bernor_mf
Advisor
Advisor

Hi @lance.xi,

 
This example displays mesh status.
Set StudyDoc = Synergy.StudyDoc()
MsgBox StudyDoc.MeshStatus

 

This example displays analysis status.
Set StudyDoc = Synergy.StudyDoc()
MsgBox StudyDoc.AnalysisStatus

 

Status can be one of the following.
New
Pending
Running
Completed
Failed

 

So you need a loop to check this when "Completed", to move to next step.

 

This example runs analysis on the studyDoc.

Set StudyDoc = Synergy.StudyDoc()
StudyDoc.AnalyzeNow False, True

(Where :False : model checking is not to be performed 

True: the model solution needs to generated by the analysis )

 

Reference:
In Synergy, top-right corner, to the right of the question-mark ("?"), click the pull down arrow and select: "Synergy API Reference".

 

Hope this helps.

Regards,

Berndt

 

( If my comments are accepted, provide "Kudos" as appreciation. If your request is answered/resolved, please click the "Accept as Solution" button. Thanks.)
0 Likes

lance.xi
Enthusiast
Enthusiast

Dear Berndt,

 

I have written a look as following, while there is still a window going out.

And, the window must be closed manually first then it can goes next step.

 

How can it auto-go to next step?

 

Please advise.

 

Thanks!

 


StudyDoc.MeshNow True
MsgBox StudyDoc.MeshStatus


    If StudyDoc.MeshStatus = "Running" Then
    WScript.Sleep (50000)
 
 ElseIf StudyDoc.MeshStatus = "Completed" Then
        StudyDoc.AnalyzeNow False, True
 
    ElseIf StudyDoc.MeshStatus = "Failed" Then
       Project.Close

    End If
   

0 Likes

bernor_mf
Advisor
Advisor

Hi @lance.xi,

remove the line:

MsgBox StudyDoc.MeshStatus

 

Regards,

Berndt

 

( If my comments are accepted, provide "Kudos" as appreciation. If your request is answered/resolved, please click the "Accept as Solution" button. Thanks.)
0 Likes

lance.xi
Enthusiast
Enthusiast

Dear Berndt,

 

If remove the line, then the mesh status can not be obtained.

 

And the loop can not work.

 

How can I settle this issue?

 

Thanks!

0 Likes

bernor_mf
Advisor
Advisor

Hi @lance.xi,

the mesh status is obtained by

StudyDoc.MeshStatus

as you do.

 

You need to put it in a loop, to check condition. Something like:

https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/using-doloop-statements

or adjacent ways

 

Need to pick one way of looping that suits your needs and code.

 

Regards,

Berndt

 

( If my comments are accepted, provide "Kudos" as appreciation. If your request is answered/resolved, please click the "Accept as Solution" button. Thanks.)
0 Likes