Difference not taking the difference of everything? - openscad

I have two pieces v-piece and i-piece which are joined together with join_pieces().
Afterwards, the combination of those two pieces are meant to be differenced as a whole by two cubes in the piece() function.
The problem is the only piece showing a difference is the i_piece and not the v_piece which even though it is connected, it is left whole with no subtraction. I have removed the difference() line and checked to make sure the cubes are intersecting both pieces and they are. I have tried a union in case the difference was only accepting one object but it appears to not have changed anything.
Any suggestions, or answers to try? Thanks.
module join_pieces() {
union() {
v_piece();
translate([0,0,-1*stem_height+INSERT]) {
i_piece();
}
}
}
module piece() {
difference() {
join_pieces();
rotate([0,0,45]) {
cube([AIR,V_PIECE_WIDTH*4, RADIUS], center=true);
}
rotate([0,0,135]) {
cube([AIR,V_PIECE_WIDTH*4, RADIUS], center=true);
}
}
}
piece();

Could you show the variable definitions and the other functions used by these modules? I tried running your code with cubes replacing v_piece and i_piece and putting random numbers as the variables. It seems like your code is correct for what you want to do, running the modified version:
module join_pieces() {
union() {
translate([-2, 0, 0]){
#cube([5, 2, 2]);
}
translate([0,-2,-1*3+2]) {
cube([3, 5, 3]);
}
}
}
module piece() {
difference() {
join_pieces();
rotate([0,0,45]) {
cube([1,3*4, 4], center=true);
}
rotate([0,0,135]) {
cube([1,3*4, 4], center=true);
}
}
}
piece();
You can see that what you have here is fine.
Have you made sure none of your other functions are missing a semi-colon and used the # to display your difference pieces?

Related

Adding data to map without overwriting - Dart

I have multiple maps inside maps, such as:
Program = {'day0': {'area0': {'exercise0': 'value'}}, 'day1': {'area0': {'exercise0': 'value'}}};
And, I want to add data to 'exercise0'. But, sometimes previous data will not be set. Such as creating 'area0' without setting 'day1'.
So...
Program['day0']['area0']['exercise0'] = 'failure';
...this code doesn't work, because 'area0' is not set.
I have used addAll too:
Program.addAll({
'day${dayIndex}': {
"area0": {
'area': Chest,
'exercise0': {'exercise': Chest.exercises[0]},
},
"area1": {
'area': FrontArm,
'exercise0': {'exercise': FrontArm.exercises[0]},
}
},
});
But rn this one overwrites the existing values.

How to optimize multiple if statements in Powershell?

This is my code :
Function CleanUpOracle
{
if ($Requete)
{
$Requete.Dispose()
}
if ($ExecuteRequete)
{
$ExecuteRequete.Dispose()
}
if ($Transaction)
{
$Transaction.Dispose()
}
if ($OracleConnexion)
{
$OracleConnexion.close()
$OracleConnexion.Dispose()
}
if ($Log.id)
{
$Log.PSObject.Properties.Remove('id')
}
}
I'm testing if a variable exist then {do something}
But in the future I'll many variable to test, I don't want to have hundred lines with that.
How can I optimize this? Maybe with a switch but how?
Thanks !
If you want to conditionally call Dispose against multiple items you can stream them from a list into the ForEach-Object (whose alias is %):
#($Requete, $ExecuteRequete, $Transaction, $OracleConnexion) |
% {if($_) {$_.Dispose()} }
NOTE: I've split this onto multiple lines for readability.

How can i tell specman to terminate the test after 5 dut_erros

I need to specify to specman a maximal amount of dut_errors in the test, which after that limit the test should be terminated.
Currently i have the option to terminate the test when an error accord or never.
You can also change the check_effect to ERROR, so it will cause the run to stop. For example (I am taking here Thorsten's example, and modify it):
extend sn_util {
!count_errors: uint;
};
extend dut_error_struct {
pre_error() is also {
util.count_errors += 1;
if util.count_errors > 5 {
set_check_effect(ERROR);
};
};
};
AFAIK this does not work out of the box. You could count the errors by using a global variable and extending the error struct, something in the line of
extend sn_util {
!count_errors: uint;
count() is {
count_errors += 1;
if count_errors > 5 { stop_run() };
};
};
extend dut_error_struct {
write() is also { util.count() };
};
There might even be an object in global that does the counting already, but probably not documented.

perl code structure for post-processing

The question I have is a bit abstract, but I'll attempt to be clear in my statement. (This is something of a "rubber duck effect" post, so I'll be thankful if just typing it out gets me somewhere. Replies, however, would be brilliant!)
I have old fortran code that I can't change (at least not yet) so I'm stuck with its awkward output.
I'm using perl to post-process poorly annotated ascii output files, which, as you might imagine, are a very specialized mixture of text and numbers. "Ah, the perfect perl objective," you say. Yes, it is. But what I've come up with is pretty terrible coding, I've recently concluded.
My question is about the generic structure that folks prefer to use to achieve such an objective. As I've said, I'm not happy with the one I've chosen.
Here's some pseudocode of the structure that I've arrived at:
flag1 = 0;
flag2 = 0;
while (<INPUT>) {
if (cond1) {
do something [like parse and set a header];
flag1 = 1;
} else {
next;
}
if (flag1 == 1 && cond2) {
do something else [like process a block of data];
} else {
next;
}
}
The objective of the above code is to be able to break the processing into blocks corresponding to the poorly partitioned ascii file -- there isn't much by way of "tags" in the file, so the conditions (cond1, cond2, etc.) are involved. The purpose of having the flags set is, among other reasons, to track the progress of the code through the file.
It occurs to me now that a better structure might be
while (<INPUT>) {
do stuff;
}
while (<INPUT>) {
do other stuff;
}
In any event, if my rambling inspires any thoughts I'd appreciate hearing them.
Thank you
Your original structure is perfectly fine. You're building a state machine, and doing it in a completely reasonable way that can't really be made any more idiomatic.
The only thing you can possibly do if you wish is to modularize the code a wee bit:
our %state = (last => 0, current => 0, next => 0);
our %extra_flags = ();
sub cond1($line) { return $next_state } # Returns 0 if cond==false
sub cond2($line) { return $next_state } # Returns 0 if cond==false
our %conditions = (
0 => \&cond1
1 => \&cond2 # flag1 is set
);
while (<INPUT>) {
my $state = $state->{current};
if ($state->{next} = $conditions{$state}->($_, $state)) {
$do_stuff{$state}->{$next_state}->($line);
$state->{last} = $state->{current};
$state->{current} = $state->{next};
next;
}
}
If the file does indeed lend itself to being processed in multiple loops, that would be a much clearer way to do it than emulating that with conditionals, IMO.
If not, even if there are just a few exceptions to code around, it's probably better to stick with the original approach you describe.

more than one defaction in the body?

All, can I run more than one defaction in the body of the rule? or can I only run one?
You can define as many actions in the pre block of a rule as you want. You can have as many actions in the action block of a rule as you want (just enclose the action block in curly braces). For example,
rule first_rule {
select when pageview ".*" setting ()
pre {
notify_one = defaction() { notify("notify_one", "First defaction"); };
notify_two = defaction() { notify("notify_two", "Second defaction"); };
}
{
notify_one();
notify_two();
}
}
So I think the answer to your question is yes.
Your question is a little confusing, but I'll give it a run.
Running actions defined with defaction is just like running system defined actions.
If you want to run more then one action in a rule, you need to wrap them in {} like so:
rule foo {
select when pageview ".*"
{
notify("cheese", "brie");
notify("apple", "golden delicious");
}
}
I seem to recall that a defaction has an implicit, optional 'pre' section, followed by the action(s). To include multiple actions you do need {} as Sam says.
act1 = defaction() {
{
notify("Defaction Demo", "<ul id='demo_id'></ul>");
append("#demo-id", "<li>cheese: brie</li>");
append("#demo-id", "<li>apple: golden delicious</li>");
}
};
That works out to defaction() { { ... } }; but the extra curly braces are required if you want more than one action in a defaction.
See also http://docs.kynetx.com/docs/Defaction