Community
Forma Developer Forum
Welcome to Autodesk Forma Developer Forum. Share your knowledge, ask questions, and explore popular Forma API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to place a library item on the Canvas?

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
iklimis
198 Views, 2 Replies

How to place a library item on the Canvas?

Hi Forma Team,

 

Using the following code I have successfully uploaded and created a Library item (a glb file)

I am having some trouble however to place it the canvas using code
Could you give me a working example of code of how to place this library item for example at the center of the project area?? 

That would help a lot 
Thank you
Giannis

 

    const { fileId } = await Forma.integrateElements.uploadFile({ data: glbArrayBuffer });
    const { urn } = await Forma.integrateElements.createElementHierarchy({
      data: {
        rootElement: "root",
        elements: {
          root: {
            id: "root",
            properties: {
              geometry: {
                type: "File",
                format: "glb",
                s3Id: fileId,
              },
            },
          },
        },
      },
    });
   const item = await Forma.library.createItem({
     data: { name: "Pin", status: "success", urn}
    })

 


the above code produces a Library Item such this: 

 

{
    authContext: "pro_ewbhpcg7dp",
    id: "003d06da-f501-4458-b477-c54ea383165a",
    name: "Pin",
    status: "success",
    updatedAt: 1707408884692
    urn: "urn:adsk-forma-elements:integrate:pro_ewbhpcg7dp:50473c19-ef39-4e88-b18f-5ce209e5ecfa:1707408884129"
}

 

 

Labels (1)
2 REPLIES 2
Message 2 of 3
magnus.poppe.wang
in reply to: iklimis

Hi there!

You are on the correct path! After creating your element with integrateElements, you can use the Forma.proposal.addElement() function to place your element into the scene. The URN you've used for adding a Library element can be used with the addElement() function. Note that the transform property decides the placement of this element relative to the local origin of the project. 

You don't need to add the element to library for placing the element into the scene. 

Can't wait to see what you're up to during the hackathon next week! Hope this helps, and let me know how it goes 😊

Message 3 of 3
iklimis
in reply to: magnus.poppe.wang

Thanks a lot @magnus.poppe.wang !!

Worked very well!  Missed the addElement() method of the proposal Api - it is quite helpful..

 

Would have been nice if the Glb maintained the colors of the file during the upload. I suspect there is some kind of compression happening there ? 

 

Cant wait to meet you guys on Tuesday!!
Giannis

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report