CADFeko - script

Altair Forum User
Altair Forum User
Altair Employee
edited October 2020 in Community Q&A

Hi,

 

I am trying to make a simple geometry with the script editor. I'm having trouble to set a metallic medium to a certain face.

 

here is my attempt:

 

metallic = project.Media:AddMetal()

newSettings = {}
newSettings['Medium'] = project.Media:Item('Metallic1')
newSettings['Thickness'] = 0.002
substrate.Faces['Face1']:SetProperties(newSettings)

 

I get an error: Error 17901: Medium has an invalid value.

 

When I try to set directly the medium with this code:

 

substrate.Faces['Face1'].Medium=  project.Media:Item('Metallic1')

substrate.Faces['Face1'].Thickness=0.01

 

I get an error about being unable to set Thickness to 0. I think it cannot work because I need to make the media and thickness in 1 operation.

 

I tryed using the SerProperties with the GetDefaultMedia() and it works fine.

 

Do you have any suggestions?

 

Thank you

Tagged:

Answers

  • JIF
    JIF
    Altair Employee
    edited February 2018

    Hello Sneezy,

     

    You are correct in stating that you need to make both changes at the same time and the code you have in the first section is correct. The problem you are most likely running into is that you have a PEC region and what to set the faces to metal (lossy). That setup does not make sense and CADFEKO is preventing you from doing it - it will do the same if you try to do it in the GUI, not just the API. You need to set the region to free space (hollow) or a dielectric (more likely for your substrate). The following code illustrates that it works and uses the same strategy as your first piece of code. This code runs when copying it into a new script.

     

     app = cf.GetApplication() project = app.Project  -- New project project = app:NewProject()  -- Added medium 'Dielectric1' properties = cf.Dielectric.GetDefaultProperties() properties.Colour = '#CF474F' properties.Label = 'Dielectric1' Dielectric1 = project.Media:AddDielectric(properties)  -- Added medium 'Metallic1' properties = cf.Metal.GetDefaultProperties() properties.Colour = '#A747BF' properties.Label = 'Metallic1' Metallic1 = project.Media:AddMetal(properties)  -- Created geometry: cuboid 'Cuboid1' properties = cf.Cuboid.GetDefaultProperties() properties.Label = 'Cuboid1' Cuboid1 = project.Geometry:AddCuboid(properties)  -- Renamed 'Cuboid1' to 'Substrate' Cuboid1.Label = 'substrate'  -- Change the region from PEC. Here I change it to a dielectric (substrate), but free space would also work Region1 = Cuboid1.Regions['Region1'] properties = Region1:GetProperties() properties.Medium = project.Media:Item('Dielectric1') -- or use 'project.Media:GetFreeSpace()' Region1:SetProperties(properties)  -- Changed settings for geometry entities Face1 = Cuboid1.Faces['Face1'] properties = Face1:GetProperties() properties.Medium = project.Media:Item('Metallic1')  properties.Thickness = '0.002' Face1:SetProperties(properties)

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2018

    Thank you it's working perfectly!

     

    I'm also having issues with something else. I'm making a rectangle with a copper medium directly on a cuboid with a certain dielectric medium. The problem rises when I try to make a union between both geometry. The face that the copper rectangle sits on is a dielectric boundary of the cuboid. Both faces has the exact same N position (elevation).

     

    When I run the union command in my script, I get: Warning 16772 - Setting amiguous: Unable to merge medium.

     

    What I don't understand is that afterwards if I manually set the rectangle medium to copper, I do not get any warning and the model works.

     

    I would like to be able to union directly from the script a certain geometry on a face which has a dielectric boundary as medium. I was wondering if I get the warning because of the thickness of the medium and the position of both geometry.

     

    Thanks again for your time!

  • Mel
    Mel Altair Community Member
    edited February 2018

    Hi Sneezy

     

    If I understand your description correctly I would say it is not necessary to create a separate rectangle on the cuboid. Simply set the face properties of the particular face of the cuboid to copper (and of course set the thickness of this lossy metal where prompted).


    Also see ExampleGuide example number 2 for a lossy metal cuboid and dipole.

     

    Mel

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2018

    No I cannot simply do this. I'm sorry my description was not clear enough. The face of the cuboid acts like a substrate and on it sits smaller rectangles of a different medium.

  • Mel
    Mel Altair Community Member
    edited February 2018

    The warning does not occur because of the thickness. CADFEKO 'sees' two coincident faces and cannot resolve the properties of the smaller rectangle - it does not know if it should be a dielectric face or a metallic face.

     

    What about the following. It is a longer script and requires basically that you 

    1. Subtract the smaller rectangle(s) from a free space the cuboid, creating a hole
    2. Copy the smaller rectangle(s) out of the Subtract1
    3. Set the rectangle(s) properties to metallic
    4. Union with the Cuboid
    5. Set the region to dielectric

     

    app = cf.GetApplication()
    project = app.Project

    -- Added medium 'Metallic1'
    properties = cf.Metal.GetDefaultProperties()
    properties.Colour = '#7F974F'
    properties.Label = 'Metallic1'
    Metallic1 = project.Media:AddMetal(properties)

    -- Added medium 'Dielectric1'
    properties = cf.Dielectric.GetDefaultProperties()
    properties.Colour = '#37D717'
    properties.Label = 'Dielectric1'
    Dielectric1 = project.Media:AddDielectric(properties)

    -- Created geometry: cuboid 'Cuboid1'
    properties = cf.Cuboid.GetDefaultProperties()
    properties.Label = 'Cuboid1'
    Cuboid1 = project.Geometry:AddCuboid(properties)

    -- Changed settings for geometry entities
    Region1 = Cuboid1.Regions['Region1']
    properties = Region1:GetProperties()
    FreeSpace = project.Media:GetFreeSpace()
    properties.Medium = FreeSpace
    Region1:SetProperties(properties)

    -- Created geometry: rectangle 'Rectangle1'
    properties = cf.Rectangle.GetDefaultProperties()
    properties.Depth = '0.2'
    properties.Label = 'Rectangle1'
    properties.Origin.N = '1'
    properties.Origin.U = '0.5'
    properties.Origin.V = '0.5'
    properties.Width = '0.2'
    Rectangle1 = project.Geometry:AddRectangle(properties)

    -- Created geometry: subtract 'Subtract1'
    targets = { Rectangle1 }
    project.Geometry:Subtract(Cuboid1, targets)

    -- Duplicated geometry: rectangle 'Rectangle1'
    Rectangle1_1 = Rectangle1:Duplicate()

    -- Changed settings for geometry entities
    Face7 = Rectangle1_1.Faces['Face7']
    properties = Face7:GetProperties()
    properties.Medium = Metallic1
    properties.Thickness = '50e-6'
    Face7:SetProperties(properties)

    -- Created geometry: union 'Union1'
    Subtract1 = project.Geometry['Subtract1']
    targets = { Rectangle1_1, Subtract1 }
    project.Geometry:Union(targets)

    -- Changed settings for geometry entities
    Union1 = project.Geometry['Union1']
    Region2 = Union1.Regions['Region2']
    properties = Region2:GetProperties()
    properties.Medium = Dielectric1
    Region2:SetProperties(properties)