Revit API changes wall parameters: from metadata it showed the correct result, not reflected in UI however - revit-api

Using revit-python-wrapper to create Wall then adjust the Wall height and Wall offset to the ground.
Here is the code
from rpw import db
from rpw import DB
start_point = XYZ(0, 0, 0)
end_point = XYZ(45, 0, 0)
# Wrapper Line
line = Line.new(start_point, end_point)
levels = db.Collector(of_class='Level')
level_0 = levels.get_first()
wall = DB.Wall.Create(doc, line.unwrap(), level_0.Id, False)
w = db.Wall(wall)
w.parameters['Unconnected Height'].value = 2675
w.parameters['Base Offset'].value = 45
Wall created successfully in the empty Revit project.
Using snoop revit DB, only one wall is found. The ID is : 318835
Checked the parameters belonging to this Wall - 318835. The parameter 'Unconnected Height' has correct double value: 2675.0 and the parameter "Base Offset" has correct double value: 45.0.
So far, everthing is perfect and per my expectation.
But, from the UI interface, the only Wall created is shown in wrong position. In 3D view, it's above the Level 1 which height is 4000.
And from the proporty tab of the selected Wall, the two parameters are also in the wrong values.
'Unconnected Height' has correct double value: 815340.0 and the parameter "Base Offset" has correct double value: 13716.0.
When I digged into deeper, I found actually the value I changed is shown in AsDouble. However, the value I changed in the UI is shown AsValueString. Both of them are pointing to the same property. However they are different, my understanding they should be the same value but in different data format.
Am I wrong?

I figured it out now.
Internally, Revit use feet rather than mm.
So, make sure convert the mm to feet then pass it to value.
w.parameters['Unconnected Height'].value = mm_to_feet(2675)
w.parameters['Base Offset'].value = mm_to_feet(45)

Related

noUISlider - Any way to place labels within the connect segments

I have a noUiSlider with several handles to allow specifying several contiguous date periods (example = Feb to Apr, May to July, and Aug to Sept). Ideally I would like to have labels that appear centered on the connect divisions to describe what each period relates to (ex. "Current Period", "Next Period"). I was thinking I could do this by setting a centered background image on the noUi-connect divisions.
However, the noUi-connect divisions use transform (translate/scale) styling which results in my background images being scaled which I do not want.
I also thought maybe I could revise the javascript to generate an outer division around each nonUi-connect division, and I would apply the background onto the outer division instead - but I was unable to get the background from the outer division to appear.
Any other ways I could accomplish this? The only other thing I can think of it to have floating divisions defined outside of the noUiSlider object which I would need to reposition whenever I detect changes in the handle positions.
You can add an element outside of the connects and absolutely position it.
A quick version for a slider with two handles (showing the value for the first handle):
var origin = slider.querySelector('.noUi-connects');
var node = document.createElement('div');
node.style.textAlign = 'center';
node.style.position = 'absolute';
node.style.zIndex = '10';
node.style.fontSize = '10px';
origin.appendChild(node);
slider.noUiSlider.on('update', function(values, handle, unencoded, tap, positions) {
node.style.left = positions[0] + '%';
node.style.right = (100 - positions[1]) + '%';
node.innerText = values[0];
});
Just realized another approach is to set the innerHtml of the specific noUi-connect divisions to my label values. Simpler than playing with background images.
But the transform styling still affects the labels, so the end result is not better. Maybe I can load the innerHtml with an inner division that somehow ignores the transform settings but I haven't figure out how to do that yet. transform: none does not make any difference.

How to change the size and shape of a CollisionShape (3D) in runtime?

I'm trying to make my game more dynamic by making attack hitboxes scaleable. However when adding a new shape to the current CollisionShape it shows the correct radius when printing but the radius ingame is not corresponding to the new value.
The code I currently use is this:
var shape = CylinderShape.new()
shape.set_radius(new_radius)
shape.set_height(new_height)
$Spatial/CollisionShape.shape = shape
When running this I tried to print the current CollisionShape.shape.radius and it showed the new number however ingame the collisionshape is still the old shape and nothing changed (both visually with the debug option on and when testing the collision size)
So my question is: how do I change the shape or size of the shape in runtime.
Things I've already tried:
$Spatial/CollisionShape.shape.radius = new_radius
$Spatial/CollisionShape.shape.height = new_height
This gave the same result unfortunately. I've also tried to make the shape null before putting the new shape in the CollisionShape. This changed nothing aswell.
Am I missing something?
It looks like it's not possible to update a collisioon shape; you have to create a new one. I solved it like this, where I have a CSGBox which owns a StaticBody which owns a CollisionShape, and I want to make the static body's collision shape match the CSGBox:
var box : BoxShape = BoxShape.new()
box.extents.x = self.width/2
box.extents.y = self.height/2
box.extents.z = self.depth/2
$StaticBody/CollisionShape.shape = box
(This script is attached to the CSGBox).

Why isn't my path2d position updating?

I created a new path2d following the instructions in the my first game article: http://docs.godotengine.org/en/3.0/getting_started/step_by_step/your_first_game.html
I wanted to move the "box" on screen so that I could see how the mobs spawn in, but when I ran the scene, it stayed off screen.
I created a new path2d, centered this one in the middle of the screen, and it works like I wanted it to, but now I moving this one in the editor doesn't update the position in game.
What's going on?
Thanks
func _on_mobtimer_timeout():
$mobtimer.wait_time = 0.1 + randf() / 2
$mobspawn/moblocation.set_offset(randi())
var mob = Mob.instance()
add_child(mob)
var direction = $mobspawn/moblocation.rotation + PI/2
mob.position = $mobspawn/moblocation.position
direction += rand_range(-PI/8, PI/8)
mob.rotation = direction
mob.set_linear_velocity(Vector2(rand_range(200, 200 + score * 30), 0).rotated(direction))
A Node2D's position property is relative to it's parent's position. The code from the Dodge The Creeps tutorial assumes that MobPath is located at 0, 0 and fails when that assumption is false.
In your case you are taking a MobSpawnLocation's position relative to MobPath and then setting it as the new Mob's global position.
Luckily Node2D's have another property that we can use in these circumstances global_position. It can be used like this:
mob.position = $mobspawn/moblocation.global_position
http://docs.godotengine.org/en/stable/classes/class_node2d.html#member-variables
This isn't a full solution, but I found a weird workaround. Instead of changing the position in the editor, if you use the nodes on the orange box (at the intersection of orange and blue), you can kind of alternate to move the box around.

FlxG.collide not working when x>648

So I was trying to create a platformer game using HaxeFlixel, but I ran into a problem: after a FlxSprite object's x value passes 648, FlxG.collide doesn't seem to work at all. Here is a gif of the problem. As you can see, it works fine when the player's x is < 648, but when it becomes greater the FlxG.collision stops working.
The level is made of objects of the class Wall which extends FlxSprite with the only difference being that it's constructor loads the wall graphic and sets its immovable property to true. FlxG.collide is being called with player as the first argument and a FlxGroup (containing the walls) as the second argument. I'm not sure that it matters but the FlxState's super.update is being called before FlxG.collide.
Okay so I took a look at the HaxeFlixel source code (specifically the FlxG.overlap private function (line 363)), and I found that it only checks for objects inside the worldBounds FlxRect. After I knew that, all I had to do was set the bounds of that rect, which can be done with FlxG.worldBounds.set(?X:Float = 0, ?Y:Float = 0, ?Width:Float = 0, ?Height:Float = 0).

Flash CC Canvas and GSAP: How to set registration point of movieclip on stage

How would I go about changing the registration point of a movieclip labeled "tablet" placed on the stage (root) dynamically?
For example: I have the following:
var tablet = this.tablet; //movieclip labeled "tablet" on stage
function resetTablet(){
tablet.regX = tablet.width/2; //move registration point to center
tablet.regY = tablet.height/2;
}
However when I call it using GSAP:
var tl = new TimelineLite();
tl.to(tablet, 1, {alpha:1, onComplete:resetTablet})
.to(tablet, 3, {alpha:0, scaleX:1.5, scaleY:1.5})
the registration point is still set to the upper left corner rather than the center.
What am I doing wrong here? Thanks!
Registration points affect change both the transformation point, but also the position. If you set a displayobject that is 100x100 pixels to regX=50;regY=50, then it will draw from that point, moving the content 50px to the top and left. If you make that change you should also translate the clip to x=50;y=50.
An issue with you example is that there is no width or height on EaselJS content (explained here). You can get the bounds of anything generated by Flash CC using the nominalBounds property, which Flash exports as a property on every object. If you have multiple frames, you can turn on "multi-frame bounds" in the publish settings, and a frameBounds property is added to the objects as well.
Note that nominalBounds and frameBounds are not used by the getBounds method.
Here is how you might be able to approach it.
var bounds = tablet.nominalBounds;
tablet.regX = bounds.width/2;
tablet.regY = bounds.height/2;
// Optional if your actual registration point was [0,0] before:
tablet.x += tablet.regX;
tablet.y += tablet.regX;
Hope that helps.

Resources