Home
Reply
Contributor
elkott
Posts: 11

Example on building an assembly

Hello all:

 

I was wondering if smeone could share with me a simple example on building an assembly, preferrably using Scheme.

 

Thanks for your help and have a nice evening.

 

Diaa

Spatial Employee
Entity
Posts: 64

Re: Example on building an assembly

Hi Diaa,

 

The following is some sample code for creating a toy cart.  I hope it's helpful to you.

 

(env:asm-clear-all)

;; make wheel part
(define pwheel (env:active-part))
(define wheel (solid:cylinder 0 0 -2 0 0 2 10))
(define wheel_face (car (entity:faces wheel)))
(entity:set-color wheel BLACK)
(define wheel_model (model:create))
(model:set-name 'Wheel.asat)

;; make axle part
(define paxle (part:new))
(env:set-active-part paxle)
(define axle (solid:cylinder 0 0 0 0 0 30 2))
(entity:set-color axle YELLOW)
(define axle_model (model:create))
(model:set-name 'Axle.asat)

;; make steering wheel part
(define psteer_wheel (part:new))
(env:set-active-part psteer_wheel)
(define steer_wheel (solid:cylinder 0 0 2 0 0 3 6))
(define tool (solid:cylinder 0 0 2 0 0 -12 2))
(solid:unite steer_wheel tool)
(define steer_wheel_model (model:create))
(model:set-name 'Steering_Wheel.asat)

;; make chassis part
(define pchassis (part:new))
(env:set-active-part pchassis)
(define chassis (solid:block 0 0 5 20 10 45))
(entity:set-color chassis RED)
(define chassis_model (model:create))
(model:set-name 'Chassis.asat)

;; make axle (sub-)assembly containing two wheels and one axle
(define paxle_assembly (part:new))
(env:set-active-part paxle_assembly)
(define axle_assembly_model (model:create))
(model:create-assembly)
(define wheel_transf1 (transform:rotation  (position 0 0 0) (gvector 0 1 0) 90))
(define wheel_transf2 (transform:compose wheel_transf1
                                         (transform:translation (gvector 30 0 0))))
(define axle_transf (transform:rotation (position 0 0 0) (gvector 0 1 0) 90))
(define wheel_inst1 (model:add-model-ref wheel_model wheel_transf1))
(define wheel_inst2 (model:add-model-ref wheel_model wheel_transf2))
(define axle_inst (model:add-model-ref axle_model axle_transf))
(model:set-name 'Axle_Asm.asat)

;; make steering axle assembly containing an axle assembly and a steering wheel
(define psteer_axle (part:new))
(env:set-active-part psteer_axle)
(define steer_axle_model (model:create))
(model:create-assembly)
(define axle_assembly_transf1 (transform:translation (gvector 0 0 0)))
(define steer_wheel_transf (transform:rotation (position 0 0 0) (gvector 1 0 0) -135))
(set! steer_wheel_transf (transform:compose steer_wheel_transf
                                            (transform:translation (gvector 15 (/ 12 (sqrt 2)) (/ -12 (sqrt 2))))))
(define axle_assembly_inst1 (model:add-model-ref axle_assembly_model axle_assembly_transf1))
(define steer_wheel_inst (model:add-model-ref steer_wheel_model steer_wheel_transf))
(model:set-name 'Steer_Axle_Asm.asat)

;; make cart containing a chassis, a (front) steering axle assembly and a (rear) axle assembly
(define pcart (part:new))
(env:set-active-part pcart)
(define cart_model (model:create))
(model:create-assembly)
(define chassis_transf (transform:translation (gvector 5 -5 5)))
(define chassis_inst (model:add-model-ref chassis_model chassis_transf))
(define steer_axle_transf (transform:translation (gvector 0 0 60)))
(define steer_axle_inst (model:add-model-ref steer_axle_model steer_axle_transf ))
(define axle_assembly_transf2 (transform:translation (gvector 0 0 0)))
(define axle_assembly_inst2 (model:add-model-ref axle_assembly_model axle_assembly_transf2))
(model:set-name 'Cart.asat)

;; get a component handle for the left front wheel in the steering axle
(define inst_path (list axle_assembly_inst1 wheel_inst1))
(define left_front_wheel (component inst_path steer_axle_model))
(component:set-color left_front_wheel RED)

;; get a component handle for the left front wheel in the cart
(define cart_left_front_wheel (component (list steer_axle_inst axle_assembly_inst1 wheel_inst1)))

Best regards,

John

Contributor
elkott
Posts: 11

Re: Example on building an assembly

Hello John:

 

Thanks a lot for yoru response. As I tried to execute your code, I received the following error to the (model:create) command:

 

 acis> (define wheel_model (model:create))
*** Error model:create: Attempted to create a model for an entity manager that already has one

 

Is there any header file that I need to include in the ACIS build to be able to execute this code?

 

Thanks again.

 

Diaa

Spatial Employee
Entity
Posts: 64

Re: Example on building an assembly

Hello Diaa,

 

The model:create Scheme extension is based upon the asmi_model_create API, which requires the asm_api.hxx header.

 

In general, when you need this kind of information quickly, you can

  1. look up the Scheme extension in the online docs (e.g., http://doc.spatial.com/index.php/SchemeExt:Model:create) and find the APIs section, then
  2. click on the link(s) in that section to get to the reference for the API(s), where you can read the required header(s).

I hope that answers your question.  If not, let me know.

 

Best regards,

John

AR
Contributor
AR
Posts: 23

Re: Example on building an assembly

Hi Diaa

 

This error would occur if you are doing model:create twice, without calling part:new in between.

Contributor
elkott
Posts: 11

Re: Example on building an assembly

Hello John, and AR:

Thanks a lot for taking the time to respond to my questions.

John - I am sorry I forgot to mention in my earlier question that I had already included "asm_api.hxx" in the ACIS build. After receiving your message, I made sure that the files: "asm_scm.cpp", and "asm_model_typ.cpp" which contains all the Scheme commands in the example is also part of the build. I even rebuilt the solution, but am still receiving the same error which I mentioned in my previous message.

AR - I also made sure that I did not call (model:create) twice without (part:new) in between them.

 

John - Would it be too much to ask for a similar example in C++? I can always build a Scheme call to run my C++ code. I tried to follow the directions listed in the Assembly tutorial, but they were too abstract. So, any detailed instructions will be very appreciated.

 

Thanks again, and have a great day.

 

Diaa

Spatial Moderator
ybiyani
Posts: 223

Re: Example on building an assembly

Hello Diaa,

 

Further assistance on the c++ samples please create an incident with Spatial Support: https://spatial.custhelp.com/app/utils/login_form and we will be glad to assist you.

 

Regards,

Yogesh

 

Contributor
elkott
Posts: 11

Re: Example on building an assembly

Hello Yogesh:


I just submitted a question on the Spatial Suport website. The tracking number for my question is #110526-000004.


Thanks.


Diaa