Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

how do I get properties, delete a feature, and determine if a feature exists

Please login with a confirmed email address before reporting spam

I am new to the livelink with Matlab but familiar with Matlab itself. After running the code labeled below as "CODE USED" I want to know...

1. If I want to clear the 'b1' feature, how do I do this?

I've tried the clear command:

clear model.geom('geom1').feature('b1')

I get no error, but the node is still present.

2. How do I get the bezier curve points defined under property 'p'? I tried using the command:

model.geom('geom1').feature('b1').get('p')

And I get the error

Error using get
Ambiguous property found.
Object Name : com.comsol.model.impl.GeomFeatureImpl
Property Name : 'p'

3. How do I determine if a feature already exists?

For example, if I try exists(model.geom('geom1')) I get a true value. But the function seems undefined for the feature.

Thanks!

==== CODE USED =====

import com.comsol.model.*
import com.comsol.model.util.*

model = ModelUtil.create('Model');
model.modelNode.create('mod1');

model.geom.create('geom1', 2);
model.geom('geom1').lengthUnit('mm');
model.geom('geom1').feature.create('b1', 'BezierPolygon');

model.geom('geom1').feature('b1').set('w', {'1' '1' '1' '1/sqrt(2)' '1' '1' '1' '1' '1' '1' '1'});
model.geom('geom1').feature('b1').set('p', {'0' '.9' '1' '1' '1' '0' '0'; '0' '0' '0' '.1' '1' '1' '0'});

1 Reply Last Post 15.06.2012, 04:01 GMT-4

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 15.06.2012, 04:01 GMT-4
Questions such as the first one you asked are readily answered by having Comsol generate the Matlab code for you. Just open the Comsol GUI, execute whichever steps you are interested in, then save as .m file. In your case (if I understood correctly), Comsol would produce a Matlab script where the second to last line reads: model.geom('geom1').feature.remove('b1');

As for your second question, I remember I've stumbled over the same thing once. I have no idea why the get(..) method just won't return object properties. However, here's some code that works:
b1_properties = mphgetproperties(model.geom('geom1').feature('b1'));
b1_properties.p

In your last question, I guess you want to see if a feature with a given tag exists. In that case you could just look at the list returned by model.geom('geom1').feature.tags.
Questions such as the first one you asked are readily answered by having Comsol generate the Matlab code for you. Just open the Comsol GUI, execute whichever steps you are interested in, then save as .m file. In your case (if I understood correctly), Comsol would produce a Matlab script where the second to last line reads: model.geom('geom1').feature.remove('b1'); As for your second question, I remember I've stumbled over the same thing once. I have no idea why the get(..) method just won't return object properties. However, here's some code that works: b1_properties = mphgetproperties(model.geom('geom1').feature('b1')); b1_properties.p In your last question, I guess you want to see if a feature with a given tag exists. In that case you could just look at the list returned by model.geom('geom1').feature.tags.

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.