Cancel
Showing results for 
Search instead for 
Did you mean: 

Change Csys in Load Definition (API)

Legend
Legend

Hello,

 

 

In our project, we need to modify 200 load definitions (change coordinate system). We've written a small script using VB. The problem is that we have forces in the new coordinate system but load definition allow to set load values in the global rectangular coordinate system:

 

image.png

 

When we run the script and edit definition we see converted values (title contain the original value):

image.png

If we edit load definition manually we can set values in defined Csys. 

Question: How we can set using API values in defined Csys but not in global rectangular csys.

 

 

Yarko

 

 

 

 

4 REPLIES

Re: Change Csys in Load Definition (API)

Siemens Phenom Siemens Phenom
Siemens Phenom

Yarko,

 

You can definitely do this through the API (see below).  The trick is to recognize that the Load Definiton acts as a "bucket".  For example, if you open the model "wingpost.modfem" from the Examples directory in your Femap folder there is Load Set 1..Wingtip Loading as well as a Load Definition 1..250 lbs Force.

 

This Load Definiton is applied to 6 nodes in the model:

 LoadDef.png

 

If you right-click from the Model Info Tree, and choose to "Remove Definition" you will see the individual pieces of the "bucket":

 

RemoveDef.png

 

It is on this level that you must edit the coordinate system.  It would be similar if the Load Definition was defined on Geometry.  

 

The API below is an example that sets a Load Set Object ID = 1, gets it's first Load Definition, counts the number of individual loads, then uses the Load Mesh Object to change each actual individual load on node.

 

Try it on wingpost.modfem.


Sub Main
    Dim App As femap.model
    Set App = feFemap()

    Dim Ls As LoadSet
    Set Ls = App.feLoadSet

    Ls.setID = 1

    Dim Ld As LoadDefinition
    Set Ld = App.feLoadDefinition

    Ld.Get(Ld.First)
    ' rc is the count of loads in the "bucket"
    count = Ld.CountLoads()

    Dim Lm As LoadMesh
    Set Lm = App.feLoadMesh

    Lm.LoadDefinitionID = Ld.setID
    For i = 1 To count
        rc = Lm.Get(i)
        Lm.CSys = 1
        rc = Lm.Put(i)
    Next

End Sub
 

 

Re: Change Csys in Load Definition (API)

Legend
Legend

Dear RCatania,

 

 

Thank you for the detailed explanation. I didn't know that you can delete definition but keep load mesh objects.

 

I've run your script and it changes the coordinate system. But it also keeps force in the global coordinate system.

Original Force is FY=250. image.png

When the csys is changed the forces are recalculated:

image.png

But I would like to apply FY=250 in CSYS1. And it seems that I can't define that through API. Values in LMesh object are: FX=0, FY=250, FZ=0:

image.png

 

Yarko

Re: Change Csys in Load Definition (API)

Genius
Genius

Hi Yarko,

 

This is a workaround but I think it will get you there.

 

I was able to do what you describe by (1) getting the local Csys object, (2) finding the inverse of the Csys object's "matrix" property, and (3) multiplying the inverse matrix times the local load components.  What this does in converts the local loads into global loads.  The global loads are then what you want to write to your LoadMesh object.  Whenever you write the global loads to the LoadMesh object they then get converted back into local loads.

 

Option Explicit

Sub Main
    Dim App As femap.model
    Set App = feFemap()

    Dim fLM As femap.LoadMesh
	Set fLM=App.feLoadMesh

	Dim fCsys As femap.CSys
	Set fCsys=App.feCSys

	fCsys.Get(3)

	Dim transMat() As Double
	transMat=mInverse(fCsys.matrix)

	fLM.ID=fLM.NextEmptyID
	fLM.setID=1
	fLM.CSys=3
	fLM.meshID=1

	Dim localLoad(4) As Double
	localLoad(0)=100
	localLoad(1)=45
	localLoad(2)=88

	Dim globalLoad(4) As Double
	globalLoad(0)=transMat(0)*localLoad(0)+transMat(1)*localLoad(1)+transMat(2)*localLoad(2)
	globalLoad(1)=transMat(3)*localLoad(0)+transMat(4)*localLoad(1)+transMat(5)*localLoad(2)
	globalLoad(2)=transMat(6)*localLoad(0)+transMat(7)*localLoad(1)+transMat(8)*localLoad(2)

	App.feAppMessage(FCM_NORMAL,CStr(globalLoad(0)))
	App.feAppMessage(FCM_NORMAL,CStr(globalLoad(1)))
	App.feAppMessage(FCM_NORMAL,CStr(globalLoad(2)))

	fLM.type=FLT_NFORCE
	fLM.vload=globalLoad
	fLM.XOn=True
	fLM.YOn=True
	fLM.ZOn=True
	fLM.Put(fLM.ID)

	App.feViewRegenerate(0)

End Sub

Private Function mInverse(ByVal mat() As Double) As Double()

	'find matrix of minors
	Dim minorMat(8) As Double
	minorMat(0)=mat(4)*mat(8)-mat(7)*mat(5)
	minorMat(1)=mat(3)*mat(8)-mat(6)*mat(5)
	minorMat(2)=mat(3)*mat(7)-mat(6)*mat(4)

	minorMat(3)=mat(1)*mat(8)-mat(7)*mat(2)
	minorMat(4)=mat(0)*mat(8)-mat(6)*mat(2)
	minorMat(5)=mat(0)*mat(7)-mat(6)*mat(1)

	minorMat(6)=mat(1)*mat(5)-mat(4)*mat(2)
	minorMat(7)=mat(0)*mat(5)-mat(3)*mat(2)
	minorMat(8)=mat(0)*mat(4)-mat(3)*mat(1)

	'find matrix of cofactors
	Dim coMat(8) As Double
	Dim i As Byte
	For i = 0 To 8
		If i Mod 2 Then
			coMat(i)=-minorMat(i)
		Else
			coMat(i)=minorMat(i)
		End If
	Next

	'Adjugate the cofactor matrix
	Dim adjMat(8) As Double
	adjMat(0)=coMat(0)
	adjMat(1)=coMat(3)
	adjMat(2)=coMat(6)
	adjMat(3)=coMat(1)
	adjMat(4)=coMat(4)
	adjMat(5)=coMat(7)
	adjMat(6)=coMat(2)
	adjMat(7)=coMat(5)
	adjMat(8)=coMat(8)

	Dim detM As Double
	detM=mat(0)*minorMat(0)-mat(1)*minorMat(1)+mat(2)*minorMat(2)
	Dim retrn(8) As Double
	For i = 0 To 8
		retrn(i)=(1/detM)*adjMat(i)
	Next

	mInverse=retrn

End Function

Re: Change Csys in Load Definition (API)

Legend
Legend

Dear Runner,

 

 

Thank you very much. It works perfectly! Exactly what we needed.

 

Yarko